Answers for "a recursive function that calculates the sum of all digits"

0

a recursive function that calculates the sum of all digits

#include <stdio.h>

int SumOfDigits(int);

int main()
{
    int num;
    printf("enter the number: ");
    scanf("%d",&num);
    printf("the sum of all digit is %d",SumOfDigits(num));
    return 0;
}
int SumOfDigits(int num)
{
    if(num==0)  //basic condition
        return 0;
    else
        return num%10 +  SumOfDigits(num/10); //recursive procedure
}
Posted by: Guest on March-18-2022

Code answers related to "a recursive function that calculates the sum of all digits"

Browse Popular Code Answers by Language