Answer to Question #344308 in C++ for Rille

Question #344308

Construct a c++ program to compute the sum of the digits of the numbers input from the user. Display the number input by the user as well as the sum. Use for loop Control structure.

1
Expert's answer
2022-05-24T13:54:29-0400
#include<iostream>
using namespace std;

int main(){
    int n;
    int sum = 0;    
    cout<<"Enter int N:  ";
    cin>>n;
    cout<<"The sum of the digits of the number "<<n<<":  ";

    while(n != 0){
        sum = sum+ n % 10;
        n = n /10;
    }
    cout<<sum<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS