A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to find factorial using recursion.
Q:

C program to find factorial using recursion.

0

C program to find factorial using recursion.

In this program, we will read a number and then find (calculate) of factorial of that number using recursion.
What is factorial: Factorial of a number is the product of that number with their all below integers.
For example (Factorial of 5) is: !5 = 5*4*3*2*1 = 120

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Factorial program using recursion

/*C program to find factorial of a number using recursion.*/
 
#include <stdio.h>
 
//function for factorial
long int factorial(int n)
{   
    if(n==1)    return 1;
    return n*factorial(n-1);
}
int main()
{
    int num;
    long int fact=0;
     
    printf("Enter an integer number: ");
    scanf("%d",&num);
     
    fact=factorial(num);
    printf("Factorial of %d is = %ld",num,fact);
    printf("\n");   
    return 0;
}

Output

Enter an integer number: 5
Factorial of 5 is = 120

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now