Friday , December 15 2017
Home / C++ / Factorial of a number in C++

Factorial of a number in C++

(Last Updated On: October 10, 2017)

Factorial of a number in C++:

Def : Factorial of a number  is the product of all positive integers less than or equal to that number.For example

  • 4! = 4*3*2*1 = 24
  • 6! = 6*5*4*3*2*1 = 720
  • 3!=3*2*1 = 6

 

How to find factorial of a number in C++ :

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.    int i,fact=1,number;
  6.   cout<<“Enter any Number: “;
  7.  cin>>number;
  8.   for(i=1;i<=number;i++){
  9.       fact=fact*i;
  10.   }
  11.   cout<<“Factorial of “ <<number<<” is: “<<fact<<endl;
  12.   return 0;
  13. }

About Admin

Leave a Reply

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