Algorithm. One formula for computing the distance an object travels is: s = (v_i
ID: 3886886 • Letter: A
Question
Algorithm. One formula for computing the distance an object travels is: s = (v_i + v_f)t/2 where: s = distance traveled v_i = initial velocity of the object v_f = 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
Algorithm:
Vi <- Take initial velocity as input
Vf <- Take final velocity as input
t <- Total time taken while travelling
calculate s <- (Vf + Vi) * t * 1/2
output s
C Code:
#include <stdio.h>
int main() {
float vi, vf;
float distance;
float time;
printf("Enter initial velocity: ");
scanf("%f", &vi);
printf("Enter final velocity: ");
scanf("%f", &vf);
printf("Enter total time taken: ");
scanf("%f", &t);
distance = (vi + vf) * t * 1/2;
printf("Total distance travelled: %.2f ", distance);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.