Below Running code will calculate the final velocity based on user input.
Program is using formula v = u + at. The assumption is the user will enter values in decimal and time should not be negative.
//Program Name: Calculate Final Velocity.
//formula v= u + at
//u = initial velocity
//v = final velocity
//a = acceleration
//t = time
#include<stdio.h>
void main(){
//declare variable
float u,t, a, v;
//get value of initial velocity
printf("Enter the Value Of Initial Velocity ");
scanf("%f",&u);
//read value of time
printf("Enter the Value Of Time ");
scanf("%f",&t);
//Read value of acceleration
printf("Enter the Value Of acceleration ");
scanf("%f",&a);
//Calculate only if time is not negative
if( t > 0 )
{
// formula to calculate final velocity
v = ( u + ( a * t ) );
printf("With the initial velocity %.2f, time %.2f and acceleration %.2f, \n The value of final velocity is %f m/s", u, t, a, v);
}
else
{
printf("Entered time is negative");
}
}
Output
Enter the Value Of Initial Velocity 27
Enter the Value Of Time 3
Enter the Value Of acceleration 2
With the initial velocity 27.00, time 3.00 and acceleration 2.00,
The value of final velocity is 33.000000 m/s
Enter the Value Of Initial Velocity 27
Enter the Value Of Time 0
Enter the Value Of acceleration 2
Entered time is negative
Users can enter velocity-time and acceleration in decimal values so we declare variables as a float. The program also shows how to display decimal points up to 2 digits by using %.2f