The second equation of motion is used to calculate the displacement of an object under constant acceleration.

Algorithm

Without wasting any of your precious time let’s try to understand how second equation of motion is implemented

The second equation of motion is

s = u*t + 1/2 * a * t * t

s: total displacement
u: initial velocity
t: time taken by the journey
a: constant acceleration

We are considering u=0 if you want you can set initialVelocity variable value as per your choice, or you can ask it from user. Also, acceleration value is 9.8 which is equal to the gravity of earth.

In a function fallingDistance we have implemented the equation.

total_dist = 9.8 * i * i * 1/2 + u * i ;

total_dist = (4.9 * i * i) + (u * i);

Code:

   
#include<stdio.h>   
  
// this is the implementation of 2nd equations of motion.   
void fallingDistance(int x,float u){  
    float total_dist=0;  
    printf("Time\tDistance\n");  
    for (int i=1;i<=x;i++){  
        total_dist = (4.9 * (i*i)) + (u * i);  
        printf("%d s\t%f m\n",i,total_dist);  
    }  
}  
  
int main() {  
    int fallingTime=0;    

    int initialVelocity=0;  
    //printf("How much is the initial Velocity of element:");  
    //scanf("%f",&initialVelocity);  
    printf("How much seconds element is in air:");  
    scanf("%d",&fallingTime);  
    printf("\n");  
    fallingDistance(fallingTime,initialVelocity);  
 return 0;  
}  

The sample output of this code is.

Output

Thanks for reading this, for any other implementation please ask in the comment section.

If you want to check implementation of first equation of motion, please click here. implementation of first equation of motion.

Happy coding Bye, 👋