Thursday, September 20, 2012

program for sum of digits of a number

program for sum of digits  of a number
#include<stdio.h>
#include<conio.h>
void main()                // program for sum of digits  of a number
{
int n,r,s=0;
printf("Enter the value\n");
scanf("%d",&n);  //reads the digit
while(n!=0)
{
r=n%10;   
s=s+r;
n=n/10;
}
printf("%d",s);  //prints the sum of the digit
getch();
}


// program for sum of digits  of a number

No comments:

Post a Comment