반응형

// 피보나치 수열


#include <stdio.h>

 

int n1, n2, n;

int fibonacci(int n);

 

int main(void)

{
   printf("Insert first term!\n");
   scanf("%d",&n1);
   printf("Insert second term!\n");
   scanf("%d",&n2);
   printf("Insert the number of term!\n");
   scanf("%d",&n);
   printf("The term %d is %d.\n",n,fibonacci(n));
   return 0;
}

 

int fibonacci(int n)

{
   if(n==1 || n==2) 
      return 1;
   else 
      return fibonacci(n-1) + fibonacci(n-2);
}

 

 
반응형

+ Recent posts