Answer to Question #22526 in C++ for Otis
int sumDigits (long n)
Write a test program that prompts the user to enter an integer and display the sum of all its digits.
using namespace std;
int sumDigits(long n)
int result = 0;
while (n != 0)
digit = n % 10;
result += digit;
n /= 10;
cout << "Enter an integer number: ";
cin >> n;
cout << "The sum of its digits is: " << sumDigits(n) << endl;
You're welcome. We are glad to be helpful. If you really liked our service please press like-button beside answer field. Thank you!
Thank you!!.. really appreciate it!!