A test program generates five force readings according to Fi=(2.0 N)iF_i = (2.0\ \text{N})iFi=(2.0 N)i for integer indices i=1,2,3,4,5i = 1, 2, 3, 4, 5i=1,2,3,4,5. Immediately before one of the fragments below runs, the program declares
double total_N = 0.0;
Which fragment correctly includes all five readings, calculates their arithmetic mean, and prints it in newtons to one decimal place? Assume stdio.h has been included and the fragment is inside main.
for (int i = 1; i <= 5; ++i) { total_N += 2.0 * i; } printf("%.1f N\n", total_N / 5.0);
for (int i = 1; i <= 5; ++i) { total_N += 2.0 * i; } printf("%.1f N\n", total_N / 4.0);
for (int i = 1; i < 5; ++i) { total_N += 2.0 * i; } printf("%.1f N\n", total_N / 5.0);
for (int i = 1; i <= 5; ++i) { total_N = 2.0 * i; } printf("%.1f N\n", total_N / 5.0);
Unlock full course notes by signing up
Tracing a force accumulator
During a calibration simulation, four force readings are generated by the expression 2.5 + 0.5 * i, with forces measured in newtons. The following C code calculates their mean:
What value is stored in mean_N? Give your answer in N, to two decimal places.
Tracking updates to stored force readings
A test rig stores four signed force measurements as integer numbers of newtons. The following C statements update those stored values. Complete the table with the final force at each array index, entering exact integers in N.
Rejecting unsafe velocity inputs
A C program reads a signed displacement and an elapsed time to calculate average velocity. Its input code is
Assume any converted values are finite and representable. The program should reject the input whenever fewer than two values were assigned or the elapsed time is not strictly positive. Signed displacement is allowed. Which condition correctly fills the blank before the division?
Following repeated names through function calls
An engineering student checks a C function intended to adjust a digital sensor reading measured in integer counts. Determine the values of reading, first, and second in main immediately before return 0;. Enter each answer as an exact integer in counts.