commit 758a147dad59076d21f62a52c47511cc63ff969c Author: lemon Date: Thu Mar 24 12:37:43 2022 -0300 initial commit diff --git a/gravity.c b/gravity.c new file mode 100644 index 0000000..b9cc78a --- /dev/null +++ b/gravity.c @@ -0,0 +1,32 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + + /* intro */ + printf("\nWarning: In order for this calculator to work properly, you must use kg for mass, m/s2 for gravity, and mts for height.\n\n"); + printf("(The order is: m, g, h)\n\n"); + + /* variables */ + double mass, grav, height, result; + + if (argc != 4) { + printf("Invalid arguments.\n"); + return -1; + } + + /* converting arguments into float */ + mass = atof(argv[1]); + grav = atof(argv[2]); + height = atof(argv[3]); + + /* final calculation (m * g * v = x quantity of joules) */ + result = mass * grav * height; + + /* print of results */ + printf("The result is: %6.2fJ\n", result); + + return 0; + +} diff --git a/kinetic_energy.c b/kinetic_energy.c new file mode 100644 index 0000000..d73c59e --- /dev/null +++ b/kinetic_energy.c @@ -0,0 +1,34 @@ +#include +#include +#include + +int main(int argc, char *argv[]) { + + /* intro */ + printf("\nWarning: In order for this calculator to work properly, you must use kg for mass and m/s2 for velocity.\n\n"); + printf("(The order is: m, v)\n\n"); + + /* variables */ + double mass, vel, result; + + if (argc != 3) { + printf("Invalid arguments.\n"); + return -1; + } + + /* converting arguments to float */ + mass = atof(argv[1]); + vel = atof(argv[2]); + + /* km to m/s */ + vel = vel * 1000 / 3600; + + /* final calculation (½ m * v² = x quantity of joules) */ + result = (0.5 * mass * pow(vel, 2)); + + /* print of results */ + printf("The result is: %6.2fJ", result); + + return 0; + +}