vertical motion program in C-min

The code given in this post is written in C to find the max height reached, the time required to reach max height, the time required to come down, the velocity at the end of upward travel, the velocity at the end of downward return travel, and total time of travel by an object thrown vertically upward. The user will provide the initial velocity when prompted, and then the program will calculate the results and show the results.

Program in C for vertically upward motion

Code

#include <stdio.h>
#include <math.h>
int main() {
double initial_velocity, gravity = 9.81; // Gravity in m/s^2

// Prompt user for initial velocity
printf("Enter initial velocity: ");
scanf("%lf", &initial_velocity);

// Calculate time to reach max height
double time_to_max_height = initial_velocity / gravity;

// Calculate max height reached
double max_height = (initial_velocity * initial_velocity) / (2 * gravity);

// Calculate velocity at highest point
double velocity_at_highest_point = initial_velocity - gravity * time_to_max_height;

// Calculate time to come down
double time_to_come_down = sqrt(2 * max_height / gravity);

// Calculate final velocity before touching the ground again
double final_velocity = velocity_at_highest_point + gravity * time_to_come_down;

// Calculate total time of travel
double total_time = time_to_max_height + time_to_come_down;

// Display results
printf("Max height reached: %lf meters\n", max_height);
printf("Time to reach max height: %lf seconds\n", time_to_max_height);
printf("Velocity at highest point: %lf m/s\n", velocity_at_highest_point);
printf("Time to come down: %lf seconds\n", time_to_come_down);
printf("Final velocity before touching the ground: %lf m/s\n", final_velocity);
printf("Total time of travel: %lf seconds\n", total_time);

return 0;

}

output

error: Content is protected !!