diff --git a/20230417/answer.c b/20230417/answer.c new file mode 100644 index 0000000000000000000000000000000000000000..65a1dc248becb3157f2a226fc7b30df2ffb82e00 --- /dev/null +++ b/20230417/answer.c @@ -0,0 +1,6 @@ +#include "answer.h" + +int answer (void) +{ + return 23; +} diff --git a/20230417/answer.h b/20230417/answer.h new file mode 100644 index 0000000000000000000000000000000000000000..b6777e8210983d315b3ac3424a61bd9c9f0437b1 --- /dev/null +++ b/20230417/answer.h @@ -0,0 +1 @@ +extern int answer (void); diff --git a/20230417/floats-01.c b/20230417/floats-01.c new file mode 100644 index 0000000000000000000000000000000000000000..bb2266bc30c23b3432e9780645c5930d61fb94f7 --- /dev/null +++ b/20230417/floats-01.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + for (int i = 0; i < 100; i++) + printf ("%d %f", i, sin (i)); + return 0; +} diff --git a/20230417/floats-01.txt b/20230417/floats-01.txt new file mode 100644 index 0000000000000000000000000000000000000000..15de348cdd91f1296043ea4caab18afee13f1d11 --- /dev/null +++ b/20230417/floats-01.txt @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + for (int i = 0; i < 100; i++) + printf ("%d %f", i, sin (i)); + return 0; +} +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O floats-01.c -o floats-01 +/usr/bin/ld: /tmp/ccmLktQT.o: in function `main': +floats-01.c:(.text+0x1b): undefined reference to `sin' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O floats-01.c -lm -o floats-01 +cassini/home/peter/bo/2023ss/bs/20230417> diff --git a/20230417/floats-02.c b/20230417/floats-02.c new file mode 100644 index 0000000000000000000000000000000000000000..8d76a263fdd19b22fd6da546f5cac97859bbf59e --- /dev/null +++ b/20230417/floats-02.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +extern double sin (double __x) __attribute__ ((__nothrow__ , __leaf__)); extern double __sin (double __x) __attribute__ ((__nothrow__ , __leaf__)); + +int main (void) +{ + for (int i = 0; i < 100; i++) + printf ("%d %f", i, sin (i)); + return 0; +} diff --git a/20230417/floats-02.txt b/20230417/floats-02.txt new file mode 100644 index 0000000000000000000000000000000000000000..fc311fb36353cbe27a28d0c4933a70b102bfabdc --- /dev/null +++ b/20230417/floats-02.txt @@ -0,0 +1,24 @@ +#include <stdio.h> + +extern double sin (double __x) __attribute__ ((__nothrow__ , __leaf__)); extern double __sin (double __x) __attribute__ ((__nothrow__ , __leaf__)); + +int main (void) +{ + for (int i = 0; i < 100; i++) + printf ("%d %f", i, sin (i)); + return 0; +} +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O floats-02.c +/usr/bin/ld: /tmp/ccpfDJJH.o: in function `main': +floats-02.c:(.text+0x1b): undefined reference to `sin' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O floats-02.c -c +cassini/home/peter/bo/2023ss/bs/20230417> ls -l floats-02* +-rw-r--r-- 1 peter peter 267 Apr 17 16:03 floats-02.c +-rw-r--r-- 1 peter peter 1656 Apr 17 16:04 floats-02.o +cassini/home/peter/bo/2023ss/bs/20230417> gcc floats-02.o -o floats-02 +/usr/bin/ld: floats-02.o: in function `main': +floats-02.c:(.text+0x1b): undefined reference to `sin' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2023ss/bs/20230417> gcc floats-02.o -lm -o floats-02 +cassini/home/peter/bo/2023ss/bs/20230417> diff --git a/20230417/floats-03.c b/20230417/floats-03.c new file mode 100644 index 0000000000000000000000000000000000000000..69a9360ab5c9b51eea1763328a6f24184ff30662 --- /dev/null +++ b/20230417/floats-03.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + for (int i = 0; i < 100; i++) + printf ("%d %f\n", i, sin (i)); + return 0; +} diff --git a/20230417/floats-04.c b/20230417/floats-04.c new file mode 100644 index 0000000000000000000000000000000000000000..1cfd325dfc9c7837dbd610165819297af497c391 --- /dev/null +++ b/20230417/floats-04.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + for (float i = 0; i < 2 * M_PI; i += 0.1) + printf ("%10f%10f\n", i, sin (i)); + return 0; +} diff --git a/20230417/floats-05.c b/20230417/floats-05.c new file mode 100644 index 0000000000000000000000000000000000000000..2f38d2b71a308b89d0eed46be37c954ab4d14fc9 --- /dev/null +++ b/20230417/floats-05.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + for (float i = 0.0; i < 2.0 * M_PI; i += 0.1) + printf ("%10f%10f\n", i, sin (i)); + return 0; +} diff --git a/20230417/floats-06.c b/20230417/floats-06.c new file mode 100644 index 0000000000000000000000000000000000000000..84537273e8ed7fe4e6f4dfd7a1b74ecdd7cfba87 --- /dev/null +++ b/20230417/floats-06.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + printf ("2 / 3 = %f\n", 2 / 3); + printf ("2.0 / 3.0 = %f\n", 2.0 / 3.0); + return 0; +} diff --git a/20230417/floats-07.c b/20230417/floats-07.c new file mode 100644 index 0000000000000000000000000000000000000000..d637df2f7dfc3dffce5eed7ca280889412526030 --- /dev/null +++ b/20230417/floats-07.c @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <math.h> + +int main (void) +{ + for (float i = 0.0; i < 2.0 * M_PI; i += 0.001) + printf ("%10f%10f\n", i, sin (i)); + return 0; +} diff --git a/20230417/philosophy.c b/20230417/philosophy.c new file mode 100644 index 0000000000000000000000000000000000000000..e9f508a501d9ec66d02e0636a9f6c71f2c7a8594 --- /dev/null +++ b/20230417/philosophy.c @@ -0,0 +1,8 @@ +#include <stdio.h> +#include "answer.h" + +int main (void) +{ + printf ("The answer is %d.\n", answer ()); + return 0; +} diff --git a/20230417/philosophy.txt b/20230417/philosophy.txt new file mode 100644 index 0000000000000000000000000000000000000000..045880abb690264c61d80a4be30bba5f24834e79 --- /dev/null +++ b/20230417/philosophy.txt @@ -0,0 +1,26 @@ +cassini/home/peter/bo/2023ss/bs/20230417> cat philosophy.c +#include <stdio.h> +#include "answer.h" + +int main (void) +{ + printf ("The answer is %d.\n", answer ()); + return 0; +} +cassini/home/peter/bo/2023ss/bs/20230417> cat answer.h +extern int answer (void); +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O philosophy.c -o philosophy +/usr/bin/ld: /tmp/ccVKg5fk.o: in function `main': +philosophy.c:(.text+0x5): undefined reference to `answer' +collect2: error: ld returned 1 exit status +cassini/home/peter/bo/2023ss/bs/20230417> cat answer.c +#include "answer.h" + +int answer (void) +{ + return 23; +} +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O philosophy.c answer.c -o philosophy +cassini/home/peter/bo/2023ss/bs/20230417> ./philosophy +The answer is 23. +cassini/home/peter/bo/2023ss/bs/20230417> diff --git a/20230417/sum-01.c b/20230417/sum-01.c new file mode 100644 index 0000000000000000000000000000000000000000..0362b2f512138c77dde1ae1cd5e113dba56ed301 --- /dev/null +++ b/20230417/sum-01.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (float x = 1; x <= 100; x++) + S += 1.0 / (x * x); + printf ("%0.9f\n", S); + return 0; +} diff --git a/20230417/sum-02.c b/20230417/sum-02.c new file mode 100644 index 0000000000000000000000000000000000000000..c0fabe8394e2c1cb6619a0ba817ae4a7b2b67670 --- /dev/null +++ b/20230417/sum-02.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (float x = 1; x <= 1000000; x++) + S += 1.0 / (x * x); + printf ("%0.9f\n", S); + return 0; +} diff --git a/20230417/sum-03.c b/20230417/sum-03.c new file mode 100644 index 0000000000000000000000000000000000000000..472d8b7cb1fd74ac102e4a662ce7d27dfce1eb8a --- /dev/null +++ b/20230417/sum-03.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (float x = 1; x <= 10000000; x++) /* ca. 1/20 s Rechenzeit */ + S += 1.0 / (x * x); + printf ("%0.9f\n", S); + return 0; +} diff --git a/20230417/sum-04.c b/20230417/sum-04.c new file mode 100644 index 0000000000000000000000000000000000000000..c49d13aa687b7019d2b306e9f10f30da478d56f1 --- /dev/null +++ b/20230417/sum-04.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (float x = 1; x <= 100000000; x++) /* erwarte: ca. 1/2 s Rechenzeit */ + S += 1.0 / (x * x); + printf ("%0.9f\n", S); + return 0; +} diff --git a/20230417/sum-05.c b/20230417/sum-05.c new file mode 100644 index 0000000000000000000000000000000000000000..8612524abcc79fa720193972d61b623ff750e443 --- /dev/null +++ b/20230417/sum-05.c @@ -0,0 +1,14 @@ +#include <stdio.h> + +int main (void) +{ + float x = 10000000; + printf ("%f\n", x); + x++; + printf ("%f\n", x); + x = 100000000; + printf ("%f\n", x); + x++; + printf ("%f\n", x); + return 0; +} diff --git a/20230417/sum-05.txt b/20230417/sum-05.txt new file mode 100644 index 0000000000000000000000000000000000000000..eba8c946e1ab42b10868c6ea8d4056b02f666520 --- /dev/null +++ b/20230417/sum-05.txt @@ -0,0 +1,20 @@ +#include <stdio.h> + +int main (void) +{ + float x = 10000000; + printf ("%f\n", x); + x++; + printf ("%f\n", x); + x = 100000000; + printf ("%f\n", x); + x++; + printf ("%f\n", x); + return 0; +} +cassini/home/peter/bo/2023ss/bs/20230417> gcc -Wall -O sum-05.c -o sum-05 +cassini/home/peter/bo/2023ss/bs/20230417> ./sum-05 +10000000.000000 +10000001.000000 +100000000.000000 +100000000.000000 diff --git a/20230417/sum-06.c b/20230417/sum-06.c new file mode 100644 index 0000000000000000000000000000000000000000..477e087168ae5d43158edbf04261292b51ebb16d --- /dev/null +++ b/20230417/sum-06.c @@ -0,0 +1,15 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (int i = 1; i <= 100000000; i++) /* erwarte: ca. 1/2 s Rechenzeit */ + S += 1.0 / (i * i); + printf ("%0.9f\n", S); + return 0; +} diff --git a/20230417/sum-07.c b/20230417/sum-07.c new file mode 100644 index 0000000000000000000000000000000000000000..af482431387bbb2b7b4e17f8e5c658c759824322 --- /dev/null +++ b/20230417/sum-07.c @@ -0,0 +1,8 @@ +#include <stdio.h> + +int main (void) +{ + int i = 65536; + printf ("%d\n", i * i); + return 0; +} diff --git a/20230417/sum-08.c b/20230417/sum-08.c new file mode 100644 index 0000000000000000000000000000000000000000..2fec1bbec82bb170f4545ae11748e8a73fb8ae38 --- /dev/null +++ b/20230417/sum-08.c @@ -0,0 +1,18 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (int i = 1; i <= 100000000; i++) /* zum Hochzählen: int (ginge nicht mit float) */ + { + float x = i; + S += 1.0 / (x * x); /* zum Quadrieren: float (ginge nicht mit int) */ + } + printf ("%0.9f\n", S); + return 0; +} diff --git a/20230417/sum-09.c b/20230417/sum-09.c new file mode 100644 index 0000000000000000000000000000000000000000..e2c732f2d878c76989bccbfd30f1ec3b38997e28 --- /dev/null +++ b/20230417/sum-09.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <math.h> + +/* 1/1² + 1/2² + 1/3² + ... = pi²/6 */ + +int main (void) +{ + float pi = M_PI; + printf ("%0.9f\n", pi * pi / 6.0); + float S = 0.0; + for (int i = 1; i <= 100000000; i++) + { + float x = i; + S += 1.0 / (x * x); /* kleine Zahl zu großer addieren: verschwindet */ + } + printf ("%0.9f\n", S); + S = 0.0; + for (int i = 100000000; i >= 1; i--) /* Zuerst die kleinen Zahlen addieren, dann die großen. */ + { + float x = i; + S += 1.0 / (x * x); + } + printf ("%0.9f\n", S); + return 0; +}