blob: 84d358275ffa571966152fd4f2764870f4a4ac6d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <stdio.h>
#include "c23-fallback.h"
void fib2rec(size_t n, size_t buf[static 2]) [[__unsequenced__]] {
if (n > 2) {
size_t res = buf[0] + buf[1];
buf[1] = buf[0];
buf[0] = res;
fib2rec(n-1, buf);
}
}
size_t fib2(size_t n) [[__unsequenced__]] {
size_t res[2] = { 1, 1, };
fib2rec(n, res);
return res[0];
}
int main(int argc, char* argv[argc+1]) {
for (int i = 1; i < argc; ++i) { // Processes args
size_t const n = strtoull(argv[i], nullptr, 0); // arg -> size_t
printf("fib(%zu) is %zu\n",
n, fib2(n));
}
return EXIT_SUCCESS;
}
|