Algorithm. One formula for computing the distance an object travels is: s = (v_i
ID: 3886233 • Letter: A
Question
Algorithm. One formula for computing the distance an object travels is: s = (v_i + v_j) t/2 where: s = distance traveled v_i = initial velocity of the object v_j = final velocity of the object t = amount of time the object traveled a. Write an algorithm for computing the distance traveled for some object. The initial velocity, the final velocity, and the amount of time the object traveled are required inputs for this problem. The output is the distance traveled. Use plain English statements (no programming instructions required), and number your steps. For our purposes you may ignore units. a. We would like for the distance traveled to be a floating point value Discuss any issues involved in making sure that a C program will compute the correct value using the formula above.Explanation / Answer
Part 1:
Algorithm to find distance traveled by an object.
step 1 : Start/BEGIN
step 2: Declare vi,vf and t as integer data types
step 3: Initialize s=0 as integer datatype;
step 4: Read vi,vf and t;
step 5: calculate s where s=((vi+vf)*t)/2;
step 6: display s;
step 7: Stop/END
Part2:
Yes,this algorithm will work fine but you have to do little modification in your C code.
like you have to initialize vi,vf,t and s as a float or double datatype.
e.g. instead of,
int vi,vf,t;
int s=0;
you have to declare like,
double vi,vf,t;
double s=0.0;
And in the calculation part you have to write the formula as;
s=((vi+vf)*t)/2.0;
otherwise it will show compilation error.
Happy Learning !!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.