To find a factorial of a number why do we keep and = 1, and why do we multiply ans with 1 after applying the for loop ??
Why do we have to keep 'ans = 1' in order to find factorial?
HELLO @F20PYTPP0012, as factorial means multiplying all the nos. from 1 to n and initialising the ans with 1 means we are providing a variable that will store the ans and that’s all. Suppose if we take 0 then the overall result will be 0 so it is of no use and suppose if we initialise with 2 then it is also useless it will give twice the ans that we want so we just choose 2 as it best fits our need.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.