0

Write a program that inputs an integer and display the sum of its digits using while loop

6th Feb 2017, 4:04 PM
Stuy Group Study Grop
Stuy Group Study Grop - avatar
2 Respostas
+ 15
int main() { int x, sum=0; cin>>x; while(x!=0) { sum+=x%10; x/=10; } cout<<sum; return 0; }
6th Feb 2017, 4:52 PM
Filip
Filip - avatar
0
int sum=0; int num; cin>>num; while(num!=0) { sum+=num%10; num\=10; } cout<<sum;
6th Feb 2017, 4:50 PM
Ramy Gamal
Ramy Gamal - avatar