+ 3
Factoral of 4 using while statements
while loops
4 Respuestas
+ 20
int fact=1, i=4;
while(i>0)
{
fact *=i;
i--;
}
+ 3
int fact =1,x=1;
while(x<=4){
fact *= x;
x++;
}
+ 3
4! =4*3!
3! =3*2!
in general n! =n*(n-1)!
it's a typical example to use recursion
but if you have to use a while you could
multiply and decrease an integer on each iteration until you reach 1
example 5! =5*4*3*2*1