Factorial program in C++ Using Loops

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this Basic C++ Program, we will have a look at how to write a c++ program to print factorial of a number using loops.

Factorial program in C ++: the factorial of n is the product of all positive descending integers. Factorial of n is denoted by n!. For example:

3! = 3*2*1 = 6  

Here, 3! is called “3 factorial”, it is also called “3 bang” or “3 shrieks”.

The factorial is normally used in Combinations and Permutations (mathematics).

There are many ways to write the factorial program in C ++ language. 

Using Loop In C++

A loop is used to execute a block of instructions repeatedly until a particular condition is met. For example, when you display a number from 1 to 100, you may want to set the value of a variable to 1 and display it 100 times, increasing its value by 1 in each loop iteration.

Factorial Program using Loop

#include <iostream>  

using namespace std;  

int main()  

   int i,fact=1,number;    

  cout<<"Enter any Number: ";    

 cin>>number;    

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

      fact=fact*i;    

Output:

Please enter any Number: 3

Factorial of 3 is: 6 

Leave a Comment

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