Tuesday, 9 April 2013

c program to write on distance travelled d=ut+1/2at^2



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


Step 1:Start

Step2 : Read t ,dt

Step 3: Set i to 1

Step 4:Set k to dt

Step 5: Read u,a

Step 6: set s to u*k+0.5*d*k*k

Step 7: Write s

Step 8: If(k<=t) and i=1 then
            Begin
            Step 8.1 go to step 6
  And
           Else
                        Begin
            Step 8.2 :read
            Step 8.3 :if(j=0) then
            Begin
                        Step 8.3.1:Set I to 0
            End
                        Else
                                    Begin
                                                Step 8.3.2: Set I to 1
                                                Step 8.3.3: go to step 4
            End
Step 9: Stop

Step 10: End

#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();
}
12aj1f0001.blogspot.com

No comments: