+ 3

How we create a program to find factorial of a number enter by user by using loop

use loop

23rd Apr 2017, 6:49 AM
MUHAMMAD WAQAS KHAN
MUHAMMAD WAQAS KHAN - avatar
4 Answers
+ 14
Check this out. You're free to copy it. https://code.sololearn.com/ctxkoY15XjMK/?ref=app
23rd Apr 2017, 7:20 AM
Wisdom Abioye
Wisdom Abioye - avatar
+ 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?
23rd Apr 2017, 6:58 AM
mateisirghe
mateisirghe - avatar
+ 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; }
23rd Apr 2017, 8:35 AM
Rick
Rick - avatar
17th Nov 2017, 9:39 AM
#RahulVerma
#RahulVerma - avatar