Question: C programing 3. This program computes the gravitational potential energy of an object from its mass and height, but it's poorly programmed. Rewrite it to
C programing
3. This program computes the gravitational potential energy of an object from its mass and height, but it's poorly programmed. Rewrite it to make maximum use of functions and external variables (see text p. 221). See if you can make main() so small it contains nothing but function calls and the return statement.
#include
int main( )
{
float m, h, p;
float g = 9.80665;
//m = mass in kg; g = gravity in m/sec^2; h=height in meters
// p = Gravitational Potential Energy
printf ( " Enter values for mass and height (no commas) ");
scanf ( "%f %f", &m, &h ) ;
p=m*g*h;//
printf ( " The result for PE(grav) is %f Joules",p );
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
