+ 3

Factoral of 4 using while statements

while loops

14th Mar 2017, 7:06 AM
lethu
lethu - avatar
4 Answers
+ 20
int fact=1, i=4; while(i>0) { fact *=i; i--; }
14th Mar 2017, 9:33 AM
Mansi Dagla
Mansi Dagla - avatar
+ 3
int fact =1,x=1; while(x<=4){ fact *= x; x++; }
14th Mar 2017, 7:15 AM
Meharban Singh
Meharban Singh - avatar
+ 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
14th Mar 2017, 7:18 AM
Pablo De Laforé
Pablo De Laforé - avatar
24th Apr 2018, 7:42 AM
Masoud Rabiee
Masoud Rabiee - avatar