Sie sind auf Seite 1von 3

#include<stdio.h> #define gravity 9.

81 float calcMomentum(float mass, float velocity) //function containing variable ve locity and mass { return mass * velocity; // return the produt of ( mass * velocity ) } float calcWork(float force, float distance) { return force * distance; } float calcKinEnergy(float mass, float velocity) { return ((mass/2)*(velocity*velocity)); } float calcPotentialEnergy(float mass, float height) { return ( mass * gravity * height ); } float calcThermodynamic(float heat_supplied, float work_bygas) { return ( heat_supplied - work_bygas ); } void Menu(void) { printf("Which option do you want?\n"); printf("1. Momentum \n"); printf("2. Energy \n"); printf("3. Work \n"); }

int main () { char option,choice; float mass = 0, velocity = 0, distance = 0, force = 0, heat_supplied = 0, he ight = 0, work_bygas = 0; printf("Which option do you want?\n"); printf("1. Momentum \n"); printf("2. Energy \n"); printf("3. Work \n"); scanf("%c", &option); switch(option) { case '1': printf("Enter mass of the object (kg): "); scanf("%f", &mass); printf("Enter the velocity of the object (m/s): "); scanf("%f", &velocity); printf("The momentum of the object is %.2f (kg*m)/s", calcMomentum(m

ass,velocity)); break; case '2': printf("Choose an energy: \n"); printf("1.Kinetic Energy\n"); printf("2.Potential Energy\n"); printf("3.Thermodyanmic Energy\n"); scanf("%c", &choice); if ( choice == 1 ) { printf("Enter the mass of the object travelling (kg): "); scanf("%f", &mass); printf("Enter the velocity of the object (m/s): "); scanf("%f", &velocity); printf("The kinetic energy of the object is %.2f (kg*m)/s", calcKinE nergy(mass,velocity)); } else if ( choice == 2 ) { printf("Enter the mass of object (kg): "); scanf("%f", &mass); printf("Enter the height of the obejct located (m): "); scanf("%f", &height); printf("The potential energy of the object is %.2f (kg*m)/s", ca lcPotentialEnergy(mass,height)); } else if ( choice == 3 ) { printf("Enter the heat energy supplied (J): "); scanf("%f", &heat_supplied); printf("Enter the work done by the gas (+ve): "); scanf("%f", &work_bygas); printf("The thermodyanamic energy of the gas is %.2f (J)", calcT hermodynamic(heat_supplied, work_bygas)); } break; case '3': printf("Enter the force exerted by the object (N): "); scanf("%f", &force); printf("Enter the distance travelled by the object (m): "); scanf("%f", &distance); printf("The work done by the object is %.2f J", calcWork(force,dista nce)); break; default : printf("Please enter an option between 1 to 3.\n"); Menu(); }

Das könnte Ihnen auch gefallen