To display the Sum of Digits
header files
void main()
{int n;
int n1, sum=0;
cout<<"Enter the Number of N: ";
cin>> n;
while(n>0)
{
n1=n%10;
sum=sum+n1;
n=n/10;
}
cout<< sum;getch();
}
Output will be
Enter the Number of N: 258
15
Friday, May 15, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment