factorial
-
재귀적 팩토리얼Computer Engineering/자료구조 2019. 9. 7. 21:50
- Java public static int factorial(int s) { if(s==1) return 1; else return (s * factorial(s-1)); } public static void main(String[] args) { System.out.println(factorial(4)); } - Swift func factorial(item: Int) -> Int { if item == 1 { return 1 }else { return item * factorial(item: item-1) } } print(factorial(item: 4))