monoteen

1030_3-14_자료구조

Oct 29th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long int fact(int);
  4.  
  5. int main(void)
  6. {
  7.     int n, result;
  8.     printf("\n 정수를 입력하세요!!");
  9.     scanf("%d", &n);
  10.     result = fact(n);
  11.     printf("\n\n %d의 factorial 값은 %ld입니다.\n\n\n", n, result);
  12.  
  13.     return 0;
  14. }
  15.  
  16. long int fact(int n)
  17. {
  18.     int value;
  19.     if (n <= 1) {
  20.         printf("\n fact(1)함수 호출!");
  21.         printf("\n fact(1)값 1 반환!!");
  22.  
  23.         return 1;
  24.     }
  25.     else {
  26.         printf("\n fact(%d)함수 호출!", n);
  27.         value = (n * fact(n - 1));
  28.         printf("\n fact(%d)값 %ld 반환!!", n, value);
  29.  
  30.         return value;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment