컴퓨터2012.08.11 00:28

언젠간 누군가 한번 보시고 짜보길.. 


#include<stdio.h>

#include<stdlib.h>


int fib(int n);

int fib_eter(int n);


int main(int argv, char **argc)

{

int n=atoi(argc[1]);

printf("fib(%d)==%d\t%d\n", n, fib(n), fib_eter(n));


return 0;

}


int fib(int n)

{

if(n==0)

return 0;

else if(n==1)

return 1;

else

return fib(n-1)+fib(n-2);

}


int fib_eter(int n)

{

int a=0,b=1;

int c;

if(n==0)

return 0;

else if(n==1)

return 1;

while(n>1)

{

c=a+b;

a=b;

b=c;

n--;

}

return c;

}



Posted by blindfish