feat: implement recursive przestaw function with call counting and test cases
Co-authored-by: aider (openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
commit
3abea4cfb0
41
przestaw.c
Normal file
41
przestaw.c
Normal file
@ -0,0 +1,41 @@
|
||||
#include <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user