0 votes
1.5k views
in Programming by (98.9k points)
edited

Write a program in C++, to find factorial of a given number using for loop.

1 Answer

0 votes
by (98.9k points)
selected by
 
Best answer

#include <iostream>  

using namespace std;  

int main()  

{  

  int i,fact=1,number;    

  cout<<"Enter any positive Number: ";    

  cin>>number;    

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

  {    

      fact=fact*i;  //for 5! = 5*4*3*2*1  

  }    

  cout<<"Factorial of entered number" <<number<<" is: "<<fact<<endl;  

  return 0;  

}  


Output::
image

Related questions

0 votes
1 answer 363 views

Doubtly is an online community for engineering students, offering:

  • Free viva questions PDFs
  • Previous year question papers (PYQs)
  • Academic doubt solutions
  • Expert-guided solutions

Get the pro version for free by logging in!

5.7k questions

5.1k answers

108 comments

561 users

...