Factorial Program in C / Find factorial using Recursion

Competitive Exams

| 336 views

Factorial Program in C / Find factorial using Recursion

What is Factorial?

In Mathematics, factorial is a simple thing. Factorials are just products. An exclamation mark indicates the factorial. Factorial is a multiplication operation of natural numbers with all the natural numbers that are less than it. In this article, let’s discuss the factorial definition, formula and examples.

The formula to find the factorial of a number is

n! = n × (n-1) × (n-2) × (n-3) × ….× 3 × 2 × 1

Factorial of 10

For example, the factorial of 10 is written as

10! = 10 (9 × 8 × 7 × 6 × 5× 4 × 3 × 2 × 1)

Therefore, the value of 10 factorial is 3,628,800


How to find factorial in C using loog

    #include  
    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;  
    }  

Find factorial in C using Recursion

#include
int main(){
int n;
long int fact(int n);
printf("Enter Your number :");
scanf("%d",&n);

printf("The factorial of %d is %ld",n,fact(n));
return 0;
}

long int fact(int n){
       if(n>=1){
             return n*fact(n-1);
        }else{
             return 1;
       }
}

OUTPUT :

Enter a number: 5
Factorial of 5 is: 120


CONCLUSION :

There are multiple methods to calculate the factorial of a number in C. Whether it's using an iterative solution, recursion, the tgamma() method, or pointers, the most suitable method will depend on the specific needs of your program.




📢 Join Our WhatsApp Channel

Get Daily GK, Current Affairs, Amazing Facts & Quiz Updates.

🚀 Join Now
Share this Post
About Author

Quizer Team

Comments

No comments yet — be the first to comment! 💬
Leave a Comment

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

Daily Challenge

📅 Daily Quiz Challenge

Attempt today's quiz and improve your competitive exam preparation with fresh questions daily.

Start Quiz →
Mega Contest

🏆 Monthly Mega Quiz

Participate in monthly quiz contests and test your overall knowledge with top performers.

Explore Quiz →

🔥 Join Our WhatsApp Channel

Daily GK, Facts & Quiz Updates