Sunday, May 5, 2013

The total distance traveled 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<conio.h>
main()
{
    float t, u, a,distance;
    /* t- time, u- Initial velocity, a- acceleration */
    char key;
    clrscr();
    do
    {
    clrscr();
    printf("\n Enter the Initial Velocity U (m/sec1): ");
    scanf("%f",&u);
    printf("\n Enter acceleration A (m/sec2): ");
    scanf("%f",&a);
    printf("\n Enter Time T (minutes): ");
    scanf("%f",&t);

    /*Logic point*/

    distance=(u*t)+0.5*a*(t*t);

    printf("\n Travelled distance is %f",distance);
    printf("\n\n Sir, Do more enter y, e-exit \n");
    fflush(stdin);
    scanf("%c",&key);
    if(key=='e' || key=='E')
    exit();
    } while(key=='y' || key=='Y');
getch();
}

output

 Enter the Initial Velocity U (m/sec1): 1

 Enter acceleration A (m/sec2): 2

 Enter Time T (minutes): 4

 Travelled distance is 20.000000

 Sir, Do more enter y, e-exit

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More