Tuesday, 5 June 2012

The total distance travelled by vehicle in ‘t’ seconds is given by distance S = ut+1/2at2 where ‘u’ and ‘a’ are the initial velocity (m/sec.) and acceleration (m/sec2) respectively. 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<conio.h>
#include<math.h>
main()
{
  int int_count,i,time;
 float acc,dist,vel,total_dist=0;
 clrscr();
 printf("\nEnter the total no.of intervals to calculate the distance value");
 scanf("%d",&int_count);

 for(i=1;i<=int_count;i++)
  {
   printf("\nEnter the time(sec) travelled at interval %d",i);
   scanf("%d",&time);
   printf("\nEnter the current velocity of vehicle at %d interval",i);
   scanf("%d",&vel);
   printf("\n Enter the acceleration of vehicle at %d interval",i);
   scanf("%d",&acc);
   dist=(vel*time)+0.5*acc*pow(time,2);
   printf("\nThe distance travelled by vehicle at interval %d is %f",i,dist);
   total_dist+=dist;
  }
 Printf("The total distance travelled by vehicle in the specified interval time is %f",total_dist);
 getch();
}

No comments:

Post a Comment