// testing two functions at two points // using separate arrays // #include #include double my_sqrt( double x) { return exp(log(x)/2); } double my_cbrt( double x) { return exp(log(x)/3); } typedef double (*Func)(double); // Func is type of variable, pointer to function int main( void) { double x[2] = { 2, 10}; Func f[2] = { my_sqrt, my_cbrt }; Func g[2] = { sqrt, cbrt }; char *s[2] = { "sqrt", "cbrt" }; for( int j = 0; j < 2; ++j) { for( int i = 0; i < 2; ++i) { double y1 = f[j](x[i]); double y2 = g[j](x[i]); printf( "%s %g %g %g\n", s[j], 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 */