Print Sum of digits using recursion - C Program

Write a C program using recursion to print sum of digits.

Solution:

#include<stdio.h>
int sod(int n)
{
     if(n==0)
          return 0;
     else
          return(n%10+sod(n/10));
}
int main()
{
     int a,z;
     printf("Enter Number : ");
     scanf("%d",&a);
     z=sod(a);
     printf("\nSum of Digits : %d",z);
     return 0;
}


Output:

sum digits recursion