C Program to find whether a Number is Prime Or Composite using Recursion
C Program to Find Sum of Digits of a Number using Recursion
This is a C program to find sum of digits of a number using recursion.
Problem Description
This C program finds the sum of digits of a number using recursion.
Problem Solution
The following C program, using recursion, finds the sum of its digits.
advertisement
Program/Source Code
#include
int sum (int a);
int main()
{
int num, result;
printf("Enter the number: ");
scanf("%d", &num);
result = sum(num);
printf("Sum of digits in %d is %d\n", num, result);
return 0;
}
int sum (int num)
{
if (num != 0)
{
return (num % 10 + sum (num / 10));
}
else
{
.... Show More
All Chapters — C programming
Similar Questions
From Recursive program in c · C programming
C Program to Find Reverse of a Number using Recursion
C Program to Find whether a Number is Prime or Not using Recursion
C Program to find LCM of two Numbers using Recursion
C Program to Find Sum of N Numbers using Recursion
Program to print Fibonacci Series using Recursion
C Program to Find Product of 2 Numbers using Recursion
Program to find Palindrome using Recursion