1. 순환(Recursion): 하나의 함수에서 자기자신을 다시 호출

- 순환적인 문제, 자료구조를 다루는 프로그램에 적합

- 장점: 가독성이 증대, 반복에 비해 간략하게 나타낼 수 있음

- 단점: 함수 호출을 반복하게 되므로 수행속도 떨어질 수 있음, 여분의 기억공간이 더 필요, 함수의 파라미터들을 스택에 저장하는 것과 같은 사전 작업이 상당히 필요


2. 팩토리얼 수 구하기

#include <stdio.h>


int factorial(int);


int main(void)

{

int nValue = 0, nFactNum;

do 

{

printf("Enter the number to obtain the number of factorial:");

scanf("%d", &nValue);

} while (nValue <= 0);


nFactNum = factorial(nValue);

printf("=> Result of %d! = %d \n", nValue, nFactNum);

return 0;

}


int factorial(int nValue)

{

printf("- Called factorial(%d) \n", nValue);

if(nValue == 1)

return 1;


return nValue*factorial(nValue - 1);

}