Sum of digits of a three digit number

4.Write a program to find the sum of digits of a three digit number?
#include
#include
{
int a,r1,r2,rt,s;
clrscr();
printf("enter the number");
scanf("%d",&a);
r1=a%10;
r2=a%100;
rt=(r2-r1)/10;
r3=(a-r2)/100;
s=r1+rt+r3;
Printf("sum is %d",s);
getch();
}

Algorithum
1.start
2.read a
3.calculate
r1=a%10
r2=a%100
rt=(r2-r1)/10
r3=(a-r2)/100
s=r1+rt+r3
4.print s
5.stop


Result
The program is sucessfully executed and desired output is obtained

Output
enter the no
153
result is 9

0 comments:

Post a Comment