ID_DI
DI's study notes
ID_DI
전체 방문자
오늘
어제
  • 분류 전체보기 (85)
    • Deep-Learning (3)
      • CNN (2)
      • NLP (1)
    • Data_Python (6)
      • Numpy (0)
      • Matplotlib (4)
    • Python (8)
      • Python Algorithm (6)
    • Java (36)
      • Java(base) (33)
      • Java practice(base) (2)
    • Git (12)
    • Algorithm (7)
    • etc (7)
    • linux (1)
    • DeskSetup (0)
    • TIL_모각코 (4)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • staged
  • string to int
  • Python
  • 알고리즘
  • 커밋
  • 자바
  • binarySearch
  • java 기초
  • git
  • java.lang
  • matplotlib
  • java.net
  • 합병정렬
  • 정렬
  • java base
  • 파이썬
  • java
  • README.md
  • git add.
  • Github

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
ID_DI

DI's study notes

[python] factorial 함수, 재귀함수 구현
Python/Python Algorithm

[python] factorial 함수, 재귀함수 구현

2021. 8. 27. 17:02

factorial 팩토리얼 함수 구현

팩토리얼 함수의 재귀함수버전

def factorial(num): #팩토리얼 함수
    factor = 1
    for i in range(1,num+1):
        factor *= i
    return factor

def factorialRecursion(num): #팩토리얼 재귀함수
    if num == 1:
        return 1
    return num * factorialRecursion(num - 1)

실행

print(factorial(5))
print(factorialRecursion(5))

결과

120
120

'Python > Python Algorithm' 카테고리의 다른 글

[python](알고리즘) quickSort 퀵정렬(랜덤 피봇) 구현  (0) 2021.10.06
[python](알고리즘) mergeSort 병합정렬(합병정렬) 구현  (0) 2021.10.01
[python] (알고리즘) binarySearch (이진탐색) 구현  (0) 2021.08.27
[python](자료구조) Queue class 구현  (0) 2021.08.25
[python](자료구조) stack class 구현  (0) 2021.08.25
    'Python/Python Algorithm' 카테고리의 다른 글
    • [python](알고리즘) quickSort 퀵정렬(랜덤 피봇) 구현
    • [python](알고리즘) mergeSort 병합정렬(합병정렬) 구현
    • [python] (알고리즘) binarySearch (이진탐색) 구현
    • [python](자료구조) Queue class 구현
    ID_DI
    ID_DI
    Computer Vision

    티스토리툴바