Chapter:

Recursive-program-in-c

C Program to Find Sum of Digits of a Number using Recursion

This is a C program to find sum of digits of a number using recursion.

Problem Description

This C program finds the sum of digits of a number using recursion.

Problem Solution

The following C program, using recursion, finds the sum of its digits.

advertisement

Program/Source Code


#include <stdio.h>

 

int sum (int a);

 

int main()

{

    int num, result;

 

    printf("Enter the number: ");

    scanf("%d", &num);

    result = sum(num);

    printf("Sum of digits in %d is %d\n", num, result);

    return 0;

}

 

int sum (int num)

{

    if (num != 0)

Show More

All Chapters

View all Chapter and number of question available From each chapter from C-programming-