Computer Science, asked by jencyjenz196, 1 day ago

Write a C Program to find factorial of a number

Answers

Answered by latifshaikh5231
0

Program 1: Factorial program in c using for loop

#include<stdio.h>

int main(){

int i,f=1,num;

Answered by itzwolfexpro
0

Answer:

Hello Jency

Here Is Your Answer⬇

Factorial Program using loop

Let's see the factorial Program using loop.

#include<stdio.h>  

int main()    

{    

int i,fact=1,number;    

printf("Enter a number: ");    

 scanf("%d",&number);    

   for(i=1;i<=number;i++){    

     fact=fact*i;    

 }    

 printf("Factorial of %d is: %d",number,fact);    

return 0;  

}  

Output:

Enter a number: 5

Factorial of 5 is: 120

----------------------------------------------------------------------------------------------

Factorial Program using recursion in C

Let's see the factorial program in c using recursion.

#include<stdio.h>  

 

long factorial(int n)  

{  

 if (n == 0)  

   return 1;  

 else  

   return(n * factorial(n-1));  

}  

   

void main()  

{  

 int number;  

 long fact;  

 printf("Enter a number: ");  

 scanf("%d", &number);    

   

 fact = factorial(number);  

 printf("Factorial of %d is %ld\n", number, fact);  

 return 0;  

}  

Output:

Enter a number: 6

Factorial of 5 is: 720

----------------------------------------------------------------------------------------------

HAVE A NICE DAY!

Similar questions