Answers for "factorial of a number using recursion in c"

C
2

Sum of digits of a number using recursion function c

/*  
 * C Program to find Sum of Digits of a Number using Recursion
 */
#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)
    {
        return (num % 10 + sum (num / 10));
    }
    else
    {
       return 0;
    }
}
Posted by: Guest on August-25-2020
3

find factoril in C using recursion

#include<stdio.h>
fact(int i, int k){
    k=k*i;
    i--;
    if(i==0){
        return k;
    }
    else{
        fact(i, k);
    }
}
int main()
{
    int k = 1, i, factorial;
    scanf("%d",&i);
    factorial = fact(i, k);
    printf("%d\n",factorial);
    return 0;
}
Posted by: Guest on January-31-2021

Code answers related to "factorial of a number using recursion in c"

Code answers related to "C"

Browse Popular Code Answers by Language