Sunday, 13 September 2015

C PROGRAMMING-- SUM OF DIGITS

#include<stdio.h>
#include<conio.h>
void main()
{ clrscr();
int r,s=0,n;
printf("Enter the no=\n");
scanf("\n%d",&n);
while(n>0)
{ r=n%10;
n=n/10;
s=s+r;
}
printf("sum of digits=%d\n",s);

getch();
}

No comments:

Post a Comment