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

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

View File

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

Binary file not shown.

View File

@ -4,7 +4,6 @@
int global = 8150;
int sum(int,int);
int sum(int a, int b) {
@ -16,8 +15,8 @@ int sum(int a, int b) {
int main(int argc, char **argv) {
int local=4711;
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 3: %d\n", func3(2));
int tmp = 0;
@ -38,16 +37,16 @@ int main(int argc, char **argv) {
tmp = 0;
int zeroes = 0;
for(int i = 0; i <= 5; ++i) {
int func = func3(i);
tmp += func;
if(tmp == 0) zeroes++;
for(int i = 0; i <= 20; ++i) {
if(func3(i) == 0) zeroes++;
}
printf("Nullstellen: %d\n", zeroes);
recurse1(20);
printf("\n");
recurse2(20);
printf("\n");
local = sum(global, local);
return local;

Binary file not shown.