In this Program example user can enter the digit and display the sum of in output.
Program -
Program -
#include<iostream.h>
#include<conio.h>
void main()
{
int a,d,sum=0;
clrscr();
cout<<"\n
enter the number:";
cin>>a;
while(a>0)
{
d=a%10;
a/=10;
sum+=d;
}
cout<<"sum="<<sum;
getch();
}
Output -
enter the
number:234
sum=9
0 comments:
Post a Comment