Wap to get the sum of the digits of a number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,sum=0,r;
cout<<"\n enter no.";
cin>>n;
for(;num!=0;)
{
r=n%10;
n/=10;
sum+=r;
}
cout<<sum;
getch();
}
***************
OUTPUT:
enter no. 234
9
***************
No comments:
Post a Comment