Skip to content

Instantly share code, notes, and snippets.

@oknauta
Last active July 3, 2024 21:30
Show Gist options
  • Save oknauta/e11c93062fd592a173881497d1a20458 to your computer and use it in GitHub Desktop.
Save oknauta/e11c93062fd592a173881497d1a20458 to your computer and use it in GitHub Desktop.
Calculating the free fall of an object in C.
/***************************************************************
* File: physic.h
* Date: 2024-05-31 | 2024-06-01
***************************************************************/
#ifndef PHYSIC_H
#define PHYSIC_H
#include <math.h> // Library to `sqrt`
#define EARTH_GRAVITY 9.81
/**
* @brief Calculate the time to reach ground.
* @param HEIGHT_DISTANCE The distance to reach ground in meters.
* @param GRAVITY_FORCE The pull force.
*/
long double TimeToReachGround(const long double HEIGHT_DISTANCE, const long double GRAVITY_FORCE)
{
return sqrt(2 * HEIGHT_DISTANCE / GRAVITY_FORCE); //
}
#endif
/***************************************************************
* File: time_to_reach_ground.c
* Date: 2024-05-31
***************************************************************/
#include <stdio.h>
#include "physic.h"
int main(int argc, char const *argv[])
{
printf("%Lf\n", TimeToReachGround(100, EARTH_GRAVITY));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment