a program for sum of digits of three numbers in c

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a=564,t,n,sum=0;
n=a;
while(a!=0)
{
t=a%10;
sum=t+sum;
a=a/10;
}
printf(“sum of digits(%d)=%d”,n,sum);
getch();
}

output:-

sum of digits(564)=15

 

Leave a Reply