Monday 9 September 2013

c program to find sum of digits of a number

#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0,digit;
clrscr();
printf("enter any integer..");
scanf("%d",&n);
while(n!=0)
{
digit=n%10;
sum=sum+digit;
n=n/10;
}
printf("sum of digits is: %d",sum);
getch();
}

No comments:

Post a Comment