#include <iostream>
using namespace std;
int main(void) {
int sum=0,count=0,i,a,rem,num;
cout<<"Enter a number to sum its digits : ";
cin>>num;
a=num;
for(i=0;num!=0;i++)
{
rem=num%10;
sum=sum+rem;
num=num/10;
count++;
}
cout<<"\nThe sum of "<<count<<" digited number "<<a<<" is = "<<sum<<endl;
return 0;
}
No comments:
Post a Comment