From 5c120ff27d43db7547080c5e61d16befdf2837d9 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 13 Mar 2018 12:50:42 +0100 Subject: [PATCH] MP_01 umgekehrte Rekursion --- 01_ENV/a.out | Bin 6152 -> 6160 bytes 01_ENV/build-c.sh | 2 +- 01_ENV/func1.c | 20 ++++++++++---------- 01_ENV/func1.h | 2 +- 01_ENV/func1.o | Bin 1744 -> 2272 bytes 01_ENV/main.c | 13 ++++++------- 01_ENV/main.o | Bin 2504 -> 2624 bytes 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/01_ENV/a.out b/01_ENV/a.out index 63075a8948798f24bea4d469795765f04ee2d982..08b5a27195a09e389f35e0eb4bcfe86de0052471 100755 GIT binary patch delta 2144 zcmZ`)Z)_7~7=Q2D8@*R|yaC@aj$27{Im3&s-KgoB$xTmr>m*apVn7TpHYDkhdm zD(a;m!zTtm_+@5BAVi1oVKKy(KcQlX841RP_@OK%xy3r`LU8KveBQfjog_TXy}$SQ z_j{jv-s}5*5F7{&)VW&i5kkcr2^l!i^hNYwwP7P=B*bSJ7#yqUtj16gcbgLn!>p-B zz{N->N_BjmW}xJug?YYqh&Qz%K4MIUcsRp!EPWIkvDgR;%h~ssMmWbx%tB)f&=H1N zI~3Tu1wE?{^sNe!&dyhQ`g%JL#P_@&@9ZS|`rd?THrR$svBYMOF@*jI5%KZilUUe| zCD}+6=TxY7F(UO-G5u`CUlMj3cG?3Q^w=cE4o7Sa{XWsO&p~^+Xd0-biVh{s-L3W! zZ3~Ps^bdLpBhJ#?l0gd)JJee^)8w+k=IfDx2aA`oft)R^{*}J%??E!S5k#i z>-LshmS78&+@%2rh39g^RY>A}1C#Cv^&1I^jYO~{WxX+~cjM9s<)$^vYtK-lo;Tv! zuk1DOTWX6bhbJTOtlj@)If9h^@2r=Rnnp%Bc@FWZ5ZBmb4qBwjJ@~KdT4*l zf%t^84t#)a#qXWLQ3Yf@;k~GG2oZK zD*+?gGTuzDE2Tjh+%q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X{Q;EH= z#rO2=Rae6SdF598qdy?6+lE;^_y+&7tPc?z5aWzvG1nPKWP8+sScGTGAfk#G#FEw{ zHXv?8yn_YB5qH8L^25RqRC*$=-GAa(==4;%qNo~xF;5u`c#2$`945bs$~v+x=95n% zJHlDWmBn6|*-vrXzMNI+cPIT_dEc7nw!)2RU6p>XtjaXBm cHq<0HaMl2OLM=iAoDH?eAM-0L2Qz{2KcB>3VE_OC diff --git a/01_ENV/build-c.sh b/01_ENV/build-c.sh index 57fe08e..2cf356d 100755 --- a/01_ENV/build-c.sh +++ b/01_ENV/build-c.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash bash clean.sh clang-6.0 -c func1.c main.c -clang-6.0 -s func1.o main.o -lm \ No newline at end of file +clang-6.0 -s func1.o main.o -lm diff --git a/01_ENV/func1.c b/01_ENV/func1.c index fbdbe93..b85bebe 100644 --- a/01_ENV/func1.c +++ b/01_ENV/func1.c @@ -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; -} \ No newline at end of file + recurse1(count - 1); + printf(" %d", func2(count)); + } +} diff --git a/01_ENV/func1.h b/01_ENV/func1.h index 3e305c9..c3bb74b 100644 --- a/01_ENV/func1.h +++ b/01_ENV/func1.h @@ -1,5 +1,5 @@ -int func3(int x); int func2(int x); +int func3(int x); int recurse1(int x); int recurse2(int x); diff --git a/01_ENV/func1.o b/01_ENV/func1.o index 3a13b6836157540d1dfb89ee4e9e94c468fc157c..cbd08e029d53280622ffaf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?LB|u-}7hxGJl%e71!gcaX}qjh%q6}j%4<-<=j_Sxa%#I95tos znm*>OIOAq2nbgOOHNILl)=b?<>*IP7zR#KGwUnuz%Da|hFLLj!%a^(3@%fZ~8ux{E zq~n?oZzFru(bh)S^5B@OJtE9tqLwt)k;m&?QjKU`&pyU@J#yJ^c;T|Er zOMD~37f9o8pr2xN4=KhS;F-4ITA*zc7xi({AIV4SRf%Ix*d+>(;YTHXhrHk!(td<* zkY*ZO8cXx}s?RjLR4j4_0;lA2?b_7LnCDye16FpI9KS%Nd~v?uT1CzZ6~{I-n`xf! z`c@wNqau3b3^7%CJW*zCkE08Ahy diff --git a/01_ENV/main.c b/01_ENV/main.c index 361f0dc..dbce4c1 100644 --- a/01_ENV/main.c +++ b/01_ENV/main.c @@ -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; @@ -35,19 +34,19 @@ int main(int argc, char **argv) { } printf("While: %d\n", tmp); - + 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; diff --git a/01_ENV/main.o b/01_ENV/main.o index 03be1ba0efcad78d13c69dc1962db7b472e92174..05406b8c7226a49f921f38fcdf2688297bd84f08 100644 GIT binary patch delta 433 zcmX>hd_ZJ^24llS%}SvwFBpKpV?T%lfzD$Sr>IZ7Ex>qY;u|l<6O+vu14WNC*WM7} z@7D!Nch}wkYiRy4c@?8Pgazc251|!Er&B}>~BsumoF)%Q6x}KSMScCDz#5Z1yM<$yy1}YtBuD!v^-){w! z?5@4>0!RTBUFmkc!tDB@)AdDj?Tg8C8RZ%GOy0{VXR-$@zh4BbXa|_nZKDd((_Q+e z({;-WW)36s8{p_PJa3KxT0Xs>y%Yy}^kb&U`YUYB1iIJd@L&(P8pUAgM7~l1m)` Ds`YL=