+ 4

Factorial of any number?

could anyone tell me how can i find the factorial of any number in c++ ? while the rule of factorial for any number n=n*fact(n-1) ??????

27th Dec 2017, 4:28 PM
RiGeL
RiGeL - avatar
11 Antworten
27th Dec 2017, 4:34 PM
Qwqwq Rt
Qwqwq Rt - avatar
+ 4
Your welcome. This is how a community progress.
27th Dec 2017, 4:44 PM
Qwqwq Rt
Qwqwq Rt - avatar
+ 3
@rigel with for loop it is way easier
27th Dec 2017, 4:34 PM
Qwqwq Rt
Qwqwq Rt - avatar
+ 3
@Rame thank you alot!
27th Dec 2017, 4:42 PM
RiGeL
RiGeL - avatar
+ 3
@Rame absolutely😊
27th Dec 2017, 4:46 PM
RiGeL
RiGeL - avatar
+ 3
@Full Gamer that is Great!
27th Dec 2017, 7:54 PM
RiGeL
RiGeL - avatar
+ 3
https://code.sololearn.com/cPSOg2q9eB2l/?ref=app Finding Factorial using Recursion C++
27th Dec 2017, 7:58 PM
RiGeL
RiGeL - avatar
+ 2
i think I might use a do..while loop here so when the number equals to 1 the loop must stop since the factorial of any number is (n*n-1)
27th Dec 2017, 4:34 PM
RiGeL
RiGeL - avatar
+ 2
Using Recursion: #include <iostream> using namespace std; int fact(int n){ if(n==2) return 2; else return(n*fact(n-1)); } int main() { int n; cin>>n; cout<<"factorial is "<<fact(n); return 0; }
27th Dec 2017, 6:59 PM
RiGeL
RiGeL - avatar
+ 1
try also recursion
27th Dec 2017, 5:33 PM
Somasundaram R
Somasundaram R - avatar