From b3e9e62599532050fc776c5e8f076915b56c2235 Mon Sep 17 00:00:00 2001 From: David Faulkner Date: Fri, 7 Aug 2026 23:40:47 -0500 Subject: Import official C23 code examples for Modern C (Jens Gustedt, 2024) - Add official C source files, Makefile, c23-fallback.h, and LICENSE - Update README.md with study mirror notice --- fibonacci3.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 fibonacci3.c (limited to 'fibonacci3.c') diff --git a/fibonacci3.c b/fibonacci3.c new file mode 100644 index 0000000..2ed77ef --- /dev/null +++ b/fibonacci3.c @@ -0,0 +1,27 @@ +#include "c23-fallback.h" +#include + +void fib2rec(size_t n, size_t buf[2]) { + if (n) { + size_t res = buf[0] + buf[1]; + buf[1] = buf[0]; + buf[0] = res; + fib2rec(n-1, buf); + } +} + + +size_t fib2(size_t n) { + size_t res[2] = { 1, 1, }; + if (n > 2) fib2rec(n - 2, res); + return res[0]; +} + +int main(int argc, char* argv[argc+1]) { + for (int i = 1; i < argc; ++i) { // process 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; +} -- cgit v1.2.3