Write a C program to read an integer, find the sum of digits of a given integer using recursive function.
Answers
Answered by
2
int main()
{
int n,r;
printf("enter an integer");
scanf("%d",&n);
r=sum(n);
printf("the sum of digits %d",r);
getch();
return 0;
}
int sum(n)
{
if(n!=0)
{
return (n%10+sum(n/10));
}
else
{ return 0;
}
}
Similar questions
Math,
7 months ago
Geography,
7 months ago
Math,
7 months ago
Psychology,
1 year ago
Science,
1 year ago
Business Studies,
1 year ago
English,
1 year ago