10. C Program to find Mechanical Energy of a particle using E = mgh+1/2 mv2.
How does this program work?
- In this programme you will learn about how to calculate Mechanical Energy.
- This programme requires the user inputs Mass ,displacement and velocity of the body.
- In First step it calculate Potential Energy and Kinetic Energy.
- This programme perform mathematical calculation and display the result using C language.
Here is the code
#include <stdio.h>
int main(void)
{
float m,h,v,p,k,e;
printf("Enter Mass of the body\n");
scanf("%f",&m );
printf("Enter displacement of the body\n");
scanf("%f",&h );
printf("Enter velocity of the body\n");
scanf("%f",&v );
p=m*9.8*h; //To calculate Potential energy
k=0.5*m*(v*v); //To calculate Kinetic energy
e=p+k;
printf("Potential energy of the body = %f\n",p );
printf("Kinetic energy of the body = %f\n",k );
printf("Mechanical energy of a body = %f\n" , e);
}