# nの階乗を求めるメソッド(定義1) def factorial(n) ans = 1 i = 1 while i <= n ans *= i end return ans end