This is a basic C Programming language program. It is a formula calculation example program in C language.
This program uses the following statements:
- First line starts with Pre processor directives
- Pre processor directives will include required header file/s.
- It uses scanf() function for input.
- We use printf() function for output
- This program uses assignment statement for formula calculation.
- At the end show result with printf() function.
- You can compile and run the program according to the facilities provided by your IDE.
/* C Program to calculate distance covered by car when time, velocity and acceleration is given */ #include<stdio.h> int main() { float s, vi, a, t; printf("Enter intial velocity of car ="); scanf("%f", &vi); printf("Enter acceleration ="); scanf("%f", &a); printf("Enter time ="); scanf("%f", &t); s = vi * t + 1.0/2.0 *a * t * t; printf("Distance covered by car is=%f m", s); return 0; }
C Program to calculate distance covered by car
when time, velocity and acceleration is given
Write a C Program to calculate distance covered by car
when time, velocity and acceleration is given.
During the execution of this program, the user will input initial velocity in variable vi, acceleration in variable a. The program then computes the formula and assign resultant value to variable s.
Here is the sample output of this C Program. This C program computes distance covered by a car when time, velocity and acceleration are given. It use the formula s = vit + 1/2 at2
The program uses a simple assignment statement to compute the distance. The program displays the distance on screen using printf() function.