Write a program to find factorial of a given number using the recursive function method in C
Hints:
Source Code:
#include<stdio.h>
//function declaration before the main
int factorial(int n);
//main function of the program
int main()
{
int n;
scanf("%d",&n);
//call function and print the final value at a time
printf("%d", factorial(n));
return 0;
}
int factorial(int n)
{
if(n!=1)
return n*factorial(n-1);
}
Hints:
Factorial !
Example: 4! is shorthand for 4 x 3 x 2 x 1
The factorial function (symbol: !) means to multiply a series of descending natural numbers. Examples:
|
Source Code:
#include<stdio.h>
//function declaration before the main
int factorial(int n);
//main function of the program
int main()
{
int n;
scanf("%d",&n);
//call function and print the final value at a time
printf("%d", factorial(n));
return 0;
}
int factorial(int n)
{
if(n!=1)
return n*factorial(n-1);
}
#include
উত্তরমুছুনint main()
{
int r;
scanf("%d",& r);
printf("%d",fact(r));
return 0;
}
int fact(int r)
{
if(r!=1)
return r*fact(r-1);
}