Programming Examples

Recursive program in c to find the sum of digit


Write a recursive function in to Find the Sum of Digit

Solution

#include<stdio.h>
int sum_of_digit(int);
int main()
{
	int num,sod;
	printf("Enter any Number");
	scanf("%d",&num);
	sod=sum_of_digit(num);
	printf("Sum of Digit : %d",sod);
	return 0;
}
int sum_of_digit(int n)
{
	if(n==0)
	{
		return (0);
	}
	else
	{
		return (n%10+sum_of_digit(n/10));
	}
}
Output

Enter any Number124

Sum of Digit : 7


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad