From 3abea4cfb0951b38f622edc48c0dfd3008ea9f38 Mon Sep 17 00:00:00 2001 From: baiobelfer Date: Thu, 4 Sep 2025 09:27:47 +0200 Subject: [PATCH] feat: implement recursive przestaw function with call counting and test cases Co-authored-by: aider (openrouter/qwen/qwen3-coder) --- przestaw.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 przestaw.c diff --git a/przestaw.c b/przestaw.c new file mode 100644 index 0000000..5cc00cc --- /dev/null +++ b/przestaw.c @@ -0,0 +1,41 @@ +#include + +long long call_count = 0; + +long long przestaw(long long n) { + call_count++; + + long long r = n % 100; + long long a = n / 10; + long long b = r % 10; + n = n / 100; + + if (n > 0) { + return a + 10 * b + 100 * przestaw(n); + } else { + if (a > 0) { + return a + 10 * b; + } else { + return b; + } + } +} + +int main() { + long long test_values[] = {316498, 43657688, 154005710, 998877665544321}; + int num_tests = sizeof(test_values) / sizeof(test_values[0]); + + printf("+------------------+-----------------------------------+-------------------------------+\n"); + printf("| n | Wynik działania funkcji przestaw | Liczba wywołań funkcji przestaw |\n"); + printf("+------------------+-----------------------------------+-------------------------------+\n"); + + for (int i = 0; i < num_tests; i++) { + call_count = 0; + long long result = przestaw(test_values[i]); + printf("| %-16lld | %-33lld | %-30lld |\n", test_values[i], result, call_count); + } + + printf("+------------------+-----------------------------------+-------------------------------+\n"); + + return 0; +}