Second equation of motion in C language

First, we'll take input the values of initial velocity, time and acceleration, and then store the inputs in the variables.
Then, we will apply a condition, because time can't be negative.
After that, we'll apply the formula to calculate distance.
Second equation of motion in the C language
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
#include<stdio.h> | |
#include<math.h> // using math library for using pow and other mathematical operations | |
void main() | |
{ | |
//declaration of variable | |
float v, t, a, dis; | |
//getting the value of initial velocity | |
printf("Enter the Value Of Initial Velocity"); | |
scanf("%f",&v); | |
//getting the value of time | |
printf("Enter the Value Of Time"); | |
scanf("%f",&t); | |
//getting the value of acceleration | |
printf("Enter the Value Of Acceleration "); | |
scanf("%f",&a); | |
if(t>0) //applying condition since time can't be negative | |
{ | |
// formula to calculate distance | |
dis = ( (v*t) + (0.5 * a * pow(t,2.0)) ); // pow is used to apply power value | |
printf("With the inital velocity %f, time %f and acceleration %f, the value of distance is %f m", v, t, a, dis); | |
} | |
else | |
{ | |
printf("Time can't be negative"); | |
} | |
} |
Comments
Post a Comment