DISTANCE TRAVELLED


/* The total distance travelled by vehicle in 't' seconds is given by distance = ut+1/2at2
where 'u' and 'a' are the initial velocity (m/sec.) and acceleration (m/sec2).
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'.
*/


#include <stdio.h>
#include <math.h>

void main()
{
int ti, counter,time;
float a, distance=0, v;

printf("PROGRAM FOR CALC TOTAL DISTANCE TRAVELED BY A VECHILE");
printf("\nNO OF TIME INTERVALS : ");
scanf("%d",&ti);

for(counter = 1; counter <= ti; counter++)
{
printf("\nAT T%d TIME(sec) : ",counter);
scanf("%d",&time);
printf("\tVELOCITY AT %d sec (m/sec) : ",time);
scanf("%f",&v);
printf("\tACCLERATION AT %d sec (m/sec^2): ",time);
scanf("%f",&a);
distance += (v*time + (a*pow(time,2))/2);
}


printf("\nTOTAL DISTANCE TRAVELLED BY VEHICLE IN %d INTERVALS OF TIME : %f",ti,distance);
}