t.c:
CODE
/*
* Evaluate a function at three points, displaying results.
*/
void
evaluate(double f(double f_arg), double pt1, double pt2, double pt3)
{
printf("f(%.5f) = %.5f\n", pt1, f(pt1));
printf("f(%.5f) = %.5f\n", pt2, f(pt2));
printf("f(%.5f) = %.5f\n", pt3, f(pt3));
}
ex.c
#include <stdio.h>
#include <math.h>
int main(void)
{
evaluate(sin, 2,3,4);
evaluate(sqrt,2,3,4);
return(0);
}
complie:
$gcc -lm ex.c t.c
$./a.out
f(0.00000) = 0.00000
f(2.17493) = 0.82300
f(-1.99815) = -0.91007
f(0.00000) = 0.00000
f(2.17493) = 1.47476
f(-1.99815) = nan
if change ex.c, add the prototype of function evaluate
ex.c
#include <stdio.h>
#include <math.h>
void
evaluate(double f(double f_arg), double pt1, double pt2, double pt3);
int main(void)
{
evaluate(sin, 2,3,4);
evaluate(sqrt,2,3,4);
return(0);
}
compile:
$gcc -lm ex.c t.c
$./a.out
f(2.00000) = 0.90930
f(3.00000) = 0.14112
f(4.00000) = -0.75680
f(2.00000) = 1.41421
f(3.00000) = 1.73205
f(4.00000) = 2.00000
Anything wrong in the first case?