153. C Program to find sum of the given number upto single digit using recursion.
How does this program work?
- In this C programme you will learn about how to find the sum of a given number upto single digit using recursion.
Here is the code
int main(void)
{
//Program to print sum of digits upto single digit answer
long num;
int dig,sum;
printf("Enter any number : ");
scanf("%ld",&num);
printf("%ld-> ",num);
//Using Do while loop finding sum
do
{
sum = 0;
while(num!=0)
{
//Compute sum of digits
dig =num%10;
sum+=dig;
num/=10;
}
//Display final answer
printf("%d-> ",sum);
num=sum;
}
//Loop upto sum is unit digit
while(num/10!=0);
return 0;
}