working of factorial using while loop and for loop