C program to calculate sum of all digits using recursion and function
C program to calculate Total of all digits using recursion :
In this C program, we are going to learn how to sum of all digits using recursion method? Here, a number will be entered through the user and program will calculate sum of all digits.
Given a number and we have to sum of all digits using C language recursion function in C language.
Required knowledge
- for loop in c program just click
Example:
Input number:1251
Output:
Sum of total digits: 9
Sum of digits of a number program using recursion code : .
#include<stdio.h>
int digitecount(int num)
{
static int first=0;
if(num!=0)
{
first=first+(num%10);
digitecount(num/10);
}
else
return first;
}
int main()
{
int n,bb;
printf("Ente the number ");
scanf("%d",&n);
bb=digitecount(n);
printf("sum of Total digits are = %d",bb);
return 0;
}
Output

No comments