Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

LAB3

Programm 3 : C Program to find Mechanical Energy of a particle using E =


mgh+1/2 mv2.

Algorithm :

1.Start
2.Declare and initialize the variables:
 mass (m) of the particle (in kilograms)
 height (h) (in meters)
 velocity (v) of the particle (in meters per second)
 gravitational acceleration (g) (usually 9.81 m/s^2 on Earth)
 mechanical energy (E)
3.Prompt the user to input the values of mass, height, and velocity.
4.Calculate the mechanical energy (E) using the formula E = m * g * h + 0.5
* m * v * v.
5.Display the calculated mechanical energy.
6.End

Code :

#include <stdio.h>

int main ()

double mass, height, velocity, gravitational_acceleration, mechanical_energy;

printf("Enter the mass of the particle (kg): ");// Prompt the user for input

scanf("%lf", &mass);

printf("Enter the height (m): ");

scanf("%lf", &height);

printf("Enter the velocity (m/s): ");

scanf("%lf", &velocity);
LAB3

// Set the gravitational acceleration (m/s^2)

gravitational_acceleration = 9.81; // You can change this value if needed

// Calculate the mechanical energy

mechanical_energy = mass * gravitational_acceleration * height + 0.5 *


mass * velocity * velocity;

printf("The mechanical energy of the particle is: %.2lf joules\n",


mechanical_energy); // Display the result

return 0;

Output :

You might also like