Systemnahe Programmierung in C: Funktionen als Parameter |
1#include <math.h>
2
3extern double
4integral (double a, double b, double (*f) (double))
5{
6 return (((*f) (b) + (*f) (a)) / 2) * (b - a);
7}
8
9extern double
10sqr (double x)
11{
12 return x * x;
13}
14
15int
16main (void)
17{
18 double a;
19 a = integral (0.0, 3.1415, sin);
20 a = integral (0.0, 1.0, sqr);
21
22 return 0;
23}
|
1
2typedef double (*RealFct) (double);
3
4extern double integral (double a, double b, RealFct f);
|
1#include "integral2.h"
2
3extern double
4integral (double a, double b, RealFct f)
5{
6 return ((f (b) + f (a)) / 2) * (b - a);
7}
|
Letzte Änderung: 11.01.2007 | © Prof. Dr. Uwe Schmidt |