/* Program to find
the sum of the digits of a n-digit number */
#include<stdio.h>
#include<conio.h>
void
main()
{
int n,sum=0,r;
clrscr();
printf("Enter any n-digit
number:\n");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("\nSum of digits of given
number:%d",sum);
getch();
}
OUTPUT
Enter
any n-digit number:
1234
Sum
of digits of given number:10
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.