MP_01 umgekehrte Rekursion

This commit is contained in:
Johannes Theiner 2018-03-13 12:50:42 +01:00
parent 2096abcc38
commit 5c120ff27d
7 changed files with 18 additions and 19 deletions

Binary file not shown.

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
bash clean.sh bash clean.sh
clang-6.0 -c func1.c main.c clang-6.0 -c func1.c main.c
clang-6.0 -s func1.o main.o -lm clang-6.0 -s func1.o main.o -lm

View File

@ -4,24 +4,24 @@
#define func1 #define func1
int func3(int x) { int func3(int x) {
return pow(x, 3) - 3 * pow(x, 2) - x + 3; return (x-2)*(x-4)*(x-11)*(x-18);
} }
int func2(int x) { int func2(int x) {
return pow(x, 4) - 5 * pow(x, 3) + pow(x, 2) + 5; return pow(x, 4) - 5 * pow(x, 3) + pow(x, 2) + 5;
} }
int recurse1(int count) { void recurse1(int count) {
if(count >= 0) { if(count >= 0) {
printf("Recurse 1: %d", func3(count - 1)); printf(" %d", func2(count));
return recurse1(count - 1); recurse1(count - 1);
}else return 0; }
} }
int recurse2(int count) { void recurse2(int count) {
if(count >= 0) { if(count >= 0) {
printf("Recurse 2: %d", func3(count - 1)); recurse1(count - 1);
return recurse1(count - 1); printf(" %d", func2(count));
}else return 0; }
} }

View File

@ -1,5 +1,5 @@
int func3(int x);
int func2(int x); int func2(int x);
int func3(int x);
int recurse1(int x); int recurse1(int x);
int recurse2(int x); int recurse2(int x);

Binary file not shown.

View File

@ -4,7 +4,6 @@
int global = 8150; int global = 8150;
int sum(int,int); int sum(int,int);
int sum(int a, int b) { int sum(int a, int b) {
@ -16,8 +15,8 @@ int sum(int a, int b) {
int main(int argc, char **argv) { int main(int argc, char **argv) {
int local=4711; int local=4711;
printf("Hello, world!\nglobal=%d local=%d\n", global, local); printf("Hello, world!\nglobal=%d local=%d\n", global, local);
printf("Funktion 1: %d\n" ,func3(2));
printf("Funktion 2: %d\n" , func2(2)); printf("Funktion 2: %d\n" , func2(2));
printf("Funktion 3: %d\n", func3(2));
int tmp = 0; int tmp = 0;
@ -35,19 +34,19 @@ int main(int argc, char **argv) {
} }
printf("While: %d\n", tmp); printf("While: %d\n", tmp);
tmp = 0; tmp = 0;
int zeroes = 0; int zeroes = 0;
for(int i = 0; i <= 5; ++i) { for(int i = 0; i <= 20; ++i) {
int func = func3(i); if(func3(i) == 0) zeroes++;
tmp += func;
if(tmp == 0) zeroes++;
} }
printf("Nullstellen: %d\n", zeroes); printf("Nullstellen: %d\n", zeroes);
recurse1(20); recurse1(20);
printf("\n");
recurse2(20); recurse2(20);
printf("\n");
local = sum(global, local); local = sum(global, local);
return local; return local;

Binary file not shown.