aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/fib.c
blob: 6254a5f569ecd095ec616027a6ac626ec651ab0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unsigned fib(unsigned x) {
   unsigned r = 0, q = 1;
   while (x--) {
      unsigned s = r + q;
      r = q;
      q = s;
   }
   return q;
}

int atoi(const char *);
int printf(const char *, ...);

int main(int argc, char **argv) {
   unsigned n = argv[1] ? atoi(argv[1]) : 10;
   printf("fib(%u) = %u\n", n, fib(n));
}

/* vim:set ts=3 sw=3 expandtab: */