C Program to Calculate Acceleration


C Program to Calculate AccelerationLearn how to find the value of acceleration in C language.


How this Program Work?

First, we're taking the value of initial velocity, final velocity and time from the user as input.

After that, we'll apply condition if time is positive then calculate the acceleration using formula we defined and print the value of acceleration.

And if time is negative then terminate the program because time can't be negative.

C Program to Calculate Acceleration


#include<stdio.h>

void main()
{

//declaration of variable
float v, u, t, acc;

/*
we're taking
v variable for initial velocity,
u variable for final velocity
t variable for time
*/

//getting the value of initial velocity from user
printf("Enter the Value Of Initial Velocity");
scanf("%f",&v);

//getting the value of final velocity from user
printf("Enter the Value Of final Velocity");
scanf("%f",&u);

//getting the value of time from user
printf("Enter the Value Of Time 'T' ");
scanf("%f",&t);

if(t>0) //applying condition since time can't be negative
{
// formula to calculate acceleration
acc = ((u - v) / t);

printf("With the inital velocity %f, time %f and acceleration %f, the value of acceleration is %f m/s", u, v, t, acc);
}
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