Second equation of motion in C language

Before going into this, we'll use a library of math.h, for mathematic operations.

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 


#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");
}
}
Related :


Comments

Popular posts from this blog

Pseudocode to Check, Number is Odd or Even

How to Create Marksheet in C

C Program to Calculate Acceleration