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


CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz