C Programming Code Examples C > Recursion Code Examples Program to Find Sum of Digits of a Number using Recursion Program to Find Sum of Digits of a Number using Recursion The following C program, using recursion, finds the sum of its digits. #include <stdio.h> int sum (int a); int main() { int j, result; printf("Enter the number: "); scanf("%d", &j); result = sum(j); printf("Sum of digits in %d is %d\n", j, result); return 0; } int sum (int j) { if (j != 0) { return (j % 10 + sum (j / 10)); } else { return 0; } }