/* ----------------------------------------------------------------------- // Figure 9.9: The importance of parameter order. // An error with parameter order. // ----------------------------------------------------------------------- // This is a void function that takes TWO ARGUMENTS. // The first argument value determines the number of marks printed // in the line and the second determines what mark is printed. */ #include #include void n_marks( double d, char ch ); /* function prototype */ /* ----------------------------------------------------------------------- */ void main ( void ) { double x, fx; /* How many characters to print */ char ch1, ch2; /* The characters to print */ printf( "\nEnter two characters to print: " ); scanf( " %c %c", &ch1, &ch2 ); printf( "\nEnter the value of x: " ); scanf( "%lg", &x ); n_marks( ch1, x ); /* Call function to print ch1 x's. */ printf( "The value of x = %.2f", x ); fx = sqrt( x ); printf( " the square root of x = %.2f \n", fx ); n_marks( fx, ch2 ); /* Call function to print sqrt(x) ch2's. */ } /* ----------------------------------------------------------------------- */ void n_marks( double n, char ch ) { int k; /* # of stars already printed */ putchar( '\n' ); for (k = 0; k < n; ++k) putchar( ch ); /* print n marks */ printf( "\n\n" ); /* flush output to screen */ }