Tuesday, May 1, 2012

Factorial Sample : input 얻어내기, function 호출, recursion

  function fact (n)   
    if n == 0 then   
       return 1   
    else   
       return n * fact(n-1)   
    end   
  end   
     
  print("enter a number:")   
  a = io.read("*number")   
  print(fact(a))   
키워드 : 입력, 함수, 재귀, recursive call
출처 : Programming in Lua, Second Edition - 2006 - by Roberto Ierusalimschy

No comments:

Post a Comment