Wednesday, 29 October 2014

Sum of digit of a given number


Sum of digit of a given number




/*WAP to find out the sum of digit of a given number*/

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

OUTPUT:
enter the number:123

sum of digit is 6

No comments:

Post a Comment