/* --------------------------------------------------------------------- // Figure 5.6: The grapefruit returns. // Figure 5.8: The drop() function. // --------------------------------------------------------------------- // Determine the time it takes for a grapefruit to hit the ground when // it is dropped with no initial velocity from a helicopter hovering at // height h. Also determine the velocity of the fruit at impact. Use a // separate function to compute the time of travel of the grapefruit */ #include "tools.h" double drop( double height ); /* Prototype declaration of drop. */ void main( void ) { double h; /* height of fall (m) */ double t; /* time of fall (s) */ double v; /* terminal velocity (m/s) */ banner(); puts( "\n Calculate the time it would take for a grapefruit\n" " to fall from a helicopter at a given height.\n" ); printf( " Enter height of helicopter (meters): " ); scanf( "%lg", &h ); /* keyboard input for height */ t = drop( h ); /* Call drop. Send it the argument h. */ v = GRAVITY * t; /* velocity of grapefruit at this time */ printf( " Time of fall = %g seconds\n", t ); printf( " Velocity of the object = %g m/s\n", v ); bye(); } /* ---------------------------------------------------------------------- */ /* Time taken for an object dropped from height meters to hit the ground. */ double drop ( double height ) { double time; if (height < 0) { /* Exit gracefully after error. */ fatal( " Error: height must be >= 0. You entered \%g", height ); } time = sqrt( 2 * height / GRAVITY ); /* Calculate the time of fall */ return time; }