Factorial Program in C / Find factorial using Recursion

Education & Competitive Exam
8 Jul 2024 | 529 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.




Need a Website Like This?

We build fast, modern and responsive websites to grow your business.

Build Your Website
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 *

Popular Competitive Exam Quizzes

🤖 AI Quizer Assistant

📝 Quiz
📚 Categories
🏆 Leaderboard
📊 My Score
❓ Help
👋 Hi! I'm your AI quiz assistant for Quizer.in!

I can help you with:
• 📝 Finding quizzes
• 🏆 Checking leaderboard
• 📊 Your performance stats

Type 'help' to get started! 🚀
AI is thinking...