Programming

(C) fibonacci number

steloflute 2013. 11. 24. 15:33

#include <stdio.h>
#include <time.h>
int fib(int n){
  if(n<2) return n; else return fib(n-1)+fib(n-2);
}

int main(){
  int n;
  printf("n: ");
  scanf("%d", &n);
  clock_t t = clock();
  printf("%d\n", fib(n));
  t = clock() - t;
  printf("%d clicks (%f seconds)\n", t, (double)t / CLOCKS_PER_SEC);
  return 0;
}

'Programming' 카테고리의 다른 글

(Emacs Lisp) url-retrieve  (0) 2013.11.28
Emacs Lisp 시작하기  (0) 2013.11.27
BUFSIZ  (0) 2013.11.24
C: Linux Socket Programming, TCP, a simple HTTP client  (0) 2013.11.23
(Clojure) How to display Clojure version in REPL?  (0) 2013.11.13