#factorial of a number
1 messages · Page 1 of 1 (latest)
btw explain i dont think that logic holds true for numbers above 2,
1*3=3(right)
but 3 factorial is 6
^^
ill send a screenshot
😑
May I ask how you solved this problem if you don't understand the code?
i didnt solve it , i copied the solution .
Do you know what the definition of a factorial is?
yes
uhm so can you explain it in detail , i somewhat got the answer and i tried coding it
I will not do that, but I can guide you towards understanding it
I believe just explaining how things work is a subpar method of teaching
and learning
ok first ill tell you what i did
so we need a factorial of any number which is n*(n-1) .....x1=n !.
yup
first i took input from these things - 1) n. then i assigned a value 1 to factorial variable since factorial starts with 1
factorial =1;
sure
now im looping it until it reaches 1 so i use a for loop and increment it using a variable i, given that i should be less than or equal to the number inputted by user. i<=n, now i gets incremented. i =i+1; or i++.
but the catch over here is that i need factorial , so im factorial = factorial (initial=1)* i(which is 1 again). and im printing factorial out of the loop so that i get the factorial value.
1!=1*1
and now factorial increses to 2 after 1 loop.
2!=2*1.
3!=2*3(2 factoria value printed from previous iteration and 3 is number i)
this is what i understood.
seems to be on the right track
sometimes my brain gets confused on stuff i know
🤣
btw i think i forgot to add if else condition in the solution since factorial cant be available for negative integers and zero