Saved Bookmarks
| 1. |
Write a program to find the sum of all the digits of a number using while statement. |
|
Answer» #include<iostream.h> #include<iomainp.h> void main() { int n,temp,sum = 0,reminder; cout<<"Enter any positive whole number"; cin>>n; temp = 1; while(temp! = 0) { remainder = temp % 10; sum = sum + reminder; temp = temp/'0; } cout <<"The sum of digits of "<<n<<"is"<<sum<<endl; } |
|