Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions