408,793 views
20 votes
20 votes
Write a c++ program to find the factorial of a number.

User Boz
by
2.8k points

2 Answers

21 votes
21 votes
#include
using namespace std;
int main() {
int num,factorial=1;
cout<<" Enter Number To Find Its Factorial: ";
cin>>num;
for (int a=1;a<=num;a++) {
factorial=factorial*a;
}
cout<<"Factorial of Given Number is ="< return 0;
}
User Trampas Kirk
by
2.9k points
25 votes
25 votes

Answer:

I'm not gonna use recursion for this program.

#include <iostream>

using namespace std;

int main()

{

int input,factorial=1;

cout<<"Enter a number to get it's factorial: ";

cin>>input;

for(int i=1;i<=input;i++)

{

factorial *=i;

}

cout<<"The factorial of the number you entered is: "<<factorial;

return 0;

}

User Aung Kaung Hein
by
2.8k points