C program to find a factorial of a number.

 

01 #include<stdio.h>
02 long int factorial(int n);
03 int main()
04 {
05 int n;
06 printf("Enter the number:");
07 scanf("%d",&n);
08 printf("Factorial of %d is %ld",n,factorial(n));
09
10 return 0;
11 }
12
13 long int factorial(int n)
14 {
15 if(n<=1)
16 {
17 return(01);
18 }
19 else
20 {
21 n=n*factorial(n-1);
22 return(n);
23 }
24 }
 
OUTPUT :

Enter the number:
4
Factorial of 4 is 24

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.