Login to ask a question from 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

 

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)

    {

        return (num % 10 + sum (num / 10));

    }

    else

    {

    .... Show More

Previous Question Next Question
🔗

Similar Questions

From Recursive program in c · C programming

View All
WhatsApp