Faculty | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Faculty

Is it possible to calculate the faculty (n!) with a for lus?

28th Feb 2019, 10:08 PM
vicky
3 Answers
+ 2
int num = 5; int faculty = 1; for (int i = 1; i <= num; i++){ faculty*=i; //faculty = faculty * i } i = 1 --> faculty = 1 i = 2 --> faculty = 2 i = 3 --> faculty = 6 i = 4 --> faculty = 24 i = 5 --> faculty = 120 --> 5! = 120
28th Feb 2019, 11:26 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
vicky Java. But you can take the code and adapt it to Python.
1st Mar 2019, 8:54 AM
Denise Roßberg
Denise Roßberg - avatar
0
is this in Python?
1st Mar 2019, 6:27 AM
vicky