0
I have no idea why my code didn't work
Hello, I am trying to write a program for an exercise. It consists of computing two factorials and then performing calculation with their values.There is also a condition: 1<K<N The first while loop I used to find the factorial of n is working correctly, but the second loop returns 1 and I don't understand why. The loops look perfectly identical to me. https://code.sololearn.com/cnwTie5FZWBI/?ref=app
3 Answers
+ 2
The problem is in the if condition n>k, because on every step in the while loop n is decremented => n-- until it becomes 1. Then you check n>k but n is now 1 so you don't get in the second while loop. That's why the initial value 1 remains the same. You should place that check in the beginning before the loops.
+ 1
You are welcome !
0
Thank you!