The total distance travelled by vehicle in ‘t’ seconds is given by distance = ut+1/2at^{2} where ‘u’ and ‘a’ are the initial velocity (m/sec.) and acceleration (m/sec^{2}). Write C program to find the distance travelled at regular intervals of time given the values of ‘u’ and ‘a’. The program should provide the flexibility to the user to select his own time intervals and repeat the calculations for different values of ‘u’ and ‘a’.
Description:
The total distance travelled by vehicle in 't' seconds is given by distance = ut+1/2at^{2} where 'u' and 'a' are the initial velocity (m/sec.) and acceleration (m/sec2)
Algorithm:
Step 1: Start
Step 2: Read interval as integer
Step 3: for counter: 1 to interval increment counter by 1
begin
Read time, velocity, acceleration
Distance += (velocity * time + (accelerations * pow(time, 2)) / 2);
end
Step 4: Print Distance
Step 5: Stop
Flowchart:
Program:
#include<stdio.h> #include<conio.h> #include<math.h> void main() e { int i, n, sec; float d, u, a; clrscr(); printf("Enter the no. of intervals\n"); scanf("%d", &n); for(i = 1; i <= n; i++) { printf("interval: %d \n", i); printf("Enter the time in seconds \n"); scanf("%d",&sec); printf("Enter the velocity \n"); scanf("%f", &u); printf("Enter the acceleration \n"); scanf("%f", &a); d= d + (u * sec + (a * (pow(sec, 2))) / 2); } printf("Total distance travelled is %.2f", d); getch(); }
Input & Output:
Enter the number of intervals: 2 Interval: 1 Enter the time in seconds 30 Enter the velocity 35 Enter the acceleration 20 Interval: 2 Enter the time in seconds 40 Enter the velocity 45 Enter the acceleration 30 Total distance travelled is 35850.00
Viva Questions:
Q: How many types of arrays are there ?
Ans: Three types. They are one dimensional ,two dimensional and multi dimensional arrys

CreatedOct 11, 2014

UpdatedJun 07, 2017

Views32,803
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the roots of a quadratic equation
.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,,*, /, % and use switch statement
)
Write C programs that use both recursive
and nonrecursive functions
 To find the
factorial
of a given integer.  To find the
GCD
(greatest common divisor) of two given integers.