Wednesday, September 17, 2008

SUM OF DIGITS OF A NUMBER USING RECURSION in c programming language

48. SUM OF DIGITS OF A NUMBER USING RECURSION

void main()
{
int num,x;
clrscr();
printf("\nEnter a number: ");
scanf("%d",&num);
x=findsum(num);
printf("Sum of the digits of %d is: %d",num,x);
getch();
}
int r,s;
int findsum(int n)
{
if(n)
{
r=n%10;
s=s+r;
findsum(n/10);
}
else
return s;
}

No comments:

Post a Comment

Thanks to given comments.......

My Blog List