C Program to find sum of digit of number using recursion

#include <stdio.h>
int sum (int num)
{
    if (num == 0)
       return 0;
    return sum (num / 10) + num % 10;
}
int main()
{
    int num, result;
    printf("C Program to find sum of digit using recursion \n");
    printf("Enter the number: ");
    scanf("%d", &num);
    result = sum(num);
    printf("Sum of digits in %d is %d\n", num, result);
    return 0;
}

Output

C Program to find sum of digit of number using recursion

[wpusb]