source file name: sumdigit.c
void main()
{
int n,d1,d2,d3,d4,d5;
int sum=0;
clrscr();
printf("\n enter any 5 digit number: ");
scanf("%d",&n);
d1=n%10;
n=n/10;
d2=n%10;
n=n/10;
d3=n%10;
n=n/10;
d4=n%10;
n=n/10;
d5=n%10;
sum=d1+d2+d3+d4+d5;
printf("\n sum of digits=%d ",sum);
getch();
}
output:
1. enter any 5 digit number:12345
sum of digits: 15
2. enter any 5 digit number: 22222
sum of digits: 10
0 Comments
Post a Comment