/* * Example of function with input arguments and a single result * * scale function: * x --> x*10^n * Hanly and Koffman, 5ed, page 132 * */ #include #include /* Function prototype */ double scale(double x, int n); int main(void) { double num_1, xs; int num_2; /* Get values for num_1 and num_2 */ printf("Enter a real number> "); scanf("%lf", &num_1); printf("Enter an integer> "); scanf("%d", &num_2); /* function call */ xs = scale(num_1, num_2); /* display result */ printf("Result of call to function scale is %f\n", xs); return (0); } /* Function definition: scale function */ double scale(double x, int n) { double scale_factor, xs; /* local variable - 10 to power n */ scale_factor = pow(10, n); xs = x * scale_factor; return (xs); }