sum of number using loop eg: 12345=1+2+3+4+5

#include <iostream>

using namespace std;

int num,dividenum=1,modulusnum,sum=0;

int main(){



cout<<"enter a five digit number "<<endl;
cin>>num;
while(dividenum!=0){
dividenum=num/10;

modulusnum=num%10;

num=dividenum;
sum+=modulusnum;
}
cout<<"the sum of integers of a number = "<<sum<<endl;

}
Previous
Next Post »

Comments:

Disqus Shortname