+ 3
How we create a program to find factorial of a number enter by user by using loop
use loop
4 Answers
+ 14
Check this out. You're free to copy it.
https://code.sololearn.com/ctxkoY15XjMK/?ref=app
+ 1
#include <iostream>
using namespace std;
int main() {
int n,i,factorial=1;
cin>>n;
for(i=1;i<=n;i++)
{
factorial=factorial*i;
}
cout<<factorial;
return 0;
}
Is this what are you thinking about?
+ 1
// Calculates factorial for entered number.
#include <iostream>
using namespace std;
int main() {
int n = 0,
x = 0,
i = 0,
factorial = 0;
cout << "Please enter a number:";
cin >> factorial;
n = factorial; // n saves initial number.
x = factorial - 1;
for( i = x; i > 0; i-- )
{
factorial = factorial * i;
}
cout << endl << n << " factorial is: " << factorial;
return 0;
}