Sunday, 12 December 2010

program for ut+1/2at2



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'.

Description:


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).

#include<stdio.h>
main()
{
int a,u,t,t1,t2,i;
float s;
clrscr();

printf("ENTER THE VALUES OF a,u,t,t1,t2:"); scanf("%d%d%d%d%d",&a,&u,&t,&t1,&t2);

for(i=t1;i<=t2;i=i+t) // performing the looping operation for time intervals

{
s=(u*i)+(0.5*a*i*i); // calculate the total distance
 printf("\n\nthe distance travelled in %d seconds is %f ",i,s);

}
getch();
}


Input/Output:

1.ENTER THE VALUES OF a,u,t,t1,t2:1 2 3 1 5




the distance travelled in 1 seconds is 2.500000

the distance travelled in 4 seconds is 16.000000
2.ENTER THE VALUES OF a,u,t,t1,t2:0

1
2
3
4
the distance travelled in 3 seconds is 3.000000

    conclusion: The program is error free

VIVA QUESTIONS:


1)  How many types of arrays are there ?
Ans: Three types. They are one dimensional ,two dimensional and multi dimensional arrays

No comments:

Post a Comment