+ 3
How can I write c++ program to print factorial of 10
5 Answers
+ 25
#include <iostream>
using namespace std;
int main(){
int a;
cin>>a;
int f=1,b=a;
for(b;b>=2;b--)
/*or U can run from lower to higher ... from 2 to b ... as U have initially taken f to be 1 & 0!=1!=1 ... so better to start from 2! only , why waste even 1 cycle */
f*=b;
if(a>=0) //for whole numbers only
cout <<f;
return 0;
}
//or U can make 1-line recursion , just reduce the multiplication factor by 1 each time & call funcn again until that factor reaches to 1
+ 3
use a loop. in each cycle decrement the variable starting with 10 by one and multiply it with the updated value of the variable.
+ 3
well, I did something like an exercise. check out if it works.
https://code.sololearn.com/cQu3e55oJJ5Q/?ref=app
+ 2
thx let m try it
+ 2
initialize f=1, i=1
do:
f=f*i
increment i
while i<=10