Skip to content
Snippets Groups Projects
Commit 79ee7306 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Beispiele 17.4.2023: Gleitkommazahlen

parent c38dc03f
Branches
No related tags found
No related merge requests found
Showing with 253 additions and 0 deletions
#include "answer.h"
int answer (void)
{
return 23;
}
extern int answer (void);
#include <stdio.h>
#include <math.h>
int main (void)
{
for (int i = 0; i < 100; i++)
printf ("%d %f", i, sin (i));
return 0;
}
#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>
#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;
}
#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>
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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 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>
#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;
}
#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;
}
#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;
}
#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;
}
#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;
}
#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
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment