Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits
1
Expert's answer
2011-10-27T12:48:00-0400
#include <iostream> #include <conio.h>
using namespace std;
int main() { int a, S = 0, divisor = 1;
cout<<"Enter an integer number: "; cin>>a; if (a<0) a = -a; cout<<"Digits: "; if (a != 0) { while (a/divisor > 0) divisor*=10; do { divisor/=10; cout<<a/divisor<<" "; S+=a/divisor; a%=divisor; } while (divisor > 1); } else cout<<0; cout<<" Sum of digits is "<<S<<endl; getch(); return 0; }
Finding a professional expert in "partial differential equations" in the advanced level is difficult.
You can find this expert in "Assignmentexpert.com" with confidence.
Exceptional experts! I appreciate your help. God bless you!
Comments
Leave a comment