/* --------------------------------------------------------------------- // Figure 9.5: Calling a one-parameter function. // Figure 9.6: Parameters enable variations in behavior. // --------------------------------------------------------------------- // The n_stars function prints a line of k asterisks. It takes ONE // argument, the number of stars to print, and it returns nothing. */ #include #include void n_stars (double n); /* function prototype */ /*-----------------------------------------------------------------------*/ void main ( void ) { double x, fx; printf( "\nEnter the value of x: " ); scanf( "%lg", &x ); n_stars( x ); /* Call the function to print x asterisks */ printf( "The value of x = %.2f \t", x ); fx = sqrt( x ); printf( "\t the square root of x = %.2f \n", fx ); n_stars( fx ); /* Call function to print sqrt(x) asterisks */ } /*-----------------------------------------------------------------------*/ void n_stars( double n ) /* function definition */ { int k; /* # of stars already printed */ putchar( '\n' ); for (k = 0; k < n; ++k) putchar( '*' ); /* print d asterisks */ printf( "\n\n" ); /* flush output to screen */ }