Last active
July 3, 2024 21:30
-
-
Save oknauta/e11c93062fd592a173881497d1a20458 to your computer and use it in GitHub Desktop.
Calculating the free fall of an object in C.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************** | |
* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*************************************************************** | |
* 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