+ 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) ??????
11 Antworten
+ 4
Your welcome. This is how a community progress.
+ 3
@rigel
with for loop it is way easier
+ 3
@Rame thank you alot!
+ 3
@Rame absolutely😊
+ 3
@Full Gamer that is Great!
+ 3
https://code.sololearn.com/cPSOg2q9eB2l/?ref=app
Finding Factorial using Recursion C++
+ 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)
+ 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;
}
+ 1
try also recursion