Saturday, May 21, 2011

C Program to find sum of digits in number using recursion

int sumd(int);

int sumd(int x)
{
if(x==0)
return 0;
else
return (x%10)+sumd(x/10);
}

int main()
{
int a;
printf("Enter a number :");
scanf("%d",&a);
int b=sumd(a);
printf("\nSum of digits= %d",b);
getch();
}

No comments:

Post a Comment