To get Sum of digits of a integer type number using C programming
just copy the bellow code and paste it to your TurboC software. And then run the program.
#include<stdio.h>
#include<conio.h>
void main()
{
int r,s=0,n;
clrscr();
printf("enter any number : ");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
s=(s+r);
}
printf("the sum of digits is %d",s);
getch();
}
0 comments:
Post a Comment