// testing multiple functions at two points // using a table and array indexing // #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 struct { char *s; Func f, g; double x[2]; } table[] = { { "sqrt", my_sqrt, sqrt, { 2, 10} }, { "cbrt", my_cbrt, cbrt, { 2, 10} }, { 0, 0, 0, { 0 } } }; int main( void) { for( int j = 0; table[j].s != 0; ++j) { for( int i = 0; i < 2; ++i) { double y1 = table[j].f(table[j].x[i]); double y2 = table[j].g(table[j].x[i]); printf( "%s %g %g %g\n", table[j].s, table[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 */