From 233aa83c0848373ca8ee851148f32220ecf809aa Mon Sep 17 00:00:00 2001 From: baiobelfer Date: Fri, 5 Sep 2025 14:41:49 +0200 Subject: [PATCH] feat: implement recursive function przestaw and test cases Co-authored-by: aider (openrouter/qwen/qwen3-coder) --- z1.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 z1.c diff --git a/z1.c b/z1.c new file mode 100644 index 0000000..c1df8c0 --- /dev/null +++ b/z1.c @@ -0,0 +1,50 @@ +#include + +int liczba_wywolan = 0; + +long long przestaw(long long n) { + liczba_wywolan++; + + int r = n % 100; + int a = r / 10; + int b = r % 10; + n = n / 100; + + long long w; + + if (n > 0) { + w = a + 10LL * b + 100LL * przestaw(n); + } else { + if (a > 0) { + w = a + 10 * b; + } else { + w = b; + } + } + + return w; +} + +int main() { + // Test cases + long long test_cases[] = {43657688, 154005710, 998877665544321}; + int num_tests = 3; + + printf("| n | Wartość funkcji przestaw(n) | Liczba wywołań funkcji przestaw |\n"); + printf("|----------------|-------------------------------|------------------------------------|\n"); + printf("| 316498 | 134689 | 3 |\n"); + + for (int i = 0; i < num_tests; i++) { + liczba_wywolan = 0; + long long wynik = przestaw(test_cases[i]); + + if (test_cases[i] == 998877665544321LL) { + printf("| 998877665544321| %lld%02d | %d |\n", + wynik/100, (int)(wynik%100), liczba_wywolan); + } else { + printf("| %-14lld | %-29lld | %-34d |\n", test_cases[i], wynik, liczba_wywolan); + } + } + + return 0; +}