// testing multiple functions at two points // using a table and pointer // #include #include double my_sqrt( double x) { return exp(log(x)/2); } double my_cbrt( double x) { return exp(log(x)/3); } double my_atan( double x) { return atan2(x,1); } typedef double (*Func)(double); // Func is type of variable struct list { char *s; Func f, g; double x[2]; } table[] = { { "sqrt", my_sqrt, sqrt, { 2, 10} }, { "cbrt", my_cbrt, cbrt, { 2, 10} }, { "atan", my_atan, atan, { 1, 23} }, { 0, 0, 0, { 0 } } }; int main( void) { for( struct list *p = table; p->s != 0; ++p) { for( int i = 0; i < 2; ++i) { double y1 = p->f(p->x[i]); double y2 = p->g(p->x[i]); printf( "%s %g %g %g\n", p->s, p->x[i], y1, y2); } } } /* output: sqrt 2 1.41421 1.41421 sqrt 10 3.16228 3.16228 cbrt 2 1.25992 1.25992 cbrt 10 2.15443 2.15443 atan 1 0.785398 0.785398 atan 23 1.52735 1.52735 */