Answer to Question #189003 in C++ for soham

Question #189003

A five digit integer is given. Write a program in C++ to find sum of individual digits. If givennumber is 16785 then required sum is 1 + 6 + 7 + 8 + 5 = 27​

1
Expert's answer
2021-05-04T07:13:52-0400
#include<iostream>
using namespace std;
int main() {
   int num;
   int sum_digits=0;
   cout << "Enter a number : ";
   cin >> num;
   while (num != 0)
    {
      sum_digits = sum_digits + num % 10;
      num = num / 10;
    }
   cout << "The sum of the digits is : "<< sum_digits<<endl;


   return 0;
}

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