How many time is the loop body of the while statement


Refer the following program segment.

Question: Assume that all variables are of type int. z = 0; g = 0; s = 0; i = 0; while (i < 50){ scanf (“%d”, &t); s = s + t; if (t >= 0) g = g + 1; else z = z + 1; i = i + 1; }

Part 1.How many time is the loop body of the while statement executed? a) once, b) never, c) 49 times, d) 50 times, e) until a number 50 or larger is entered

Part -2 .The value stored in variable s at the end of the execution of the loop could best be described as a) the average of the numbers scanned, b) the sum of the numbers scanned, c) the largest of the numbers scanned, d) how many numbers were scanned, e) the sentinel value

Part 3.The value stored in variable z at the end of the execution of the loop could best be described. a) how many positive items were scanned, b) the sum of all positive items scanned, c) how many negative items were scanned, d) the sum of all negative items scanned, e) the sentinel value

Part 4.The loop can best be categorized as a. a) counter-controlled loop, b) sentinel-controlled loop, c) loop that computes a product, d) general condition loop, e) non of the above

Explain each and every part in depth with examples.

Request for Solution File

Ask an Expert for Answer!!
Programming Languages: How many time is the loop body of the while statement
Reference No:- TGS0943598

Expected delivery within 24 Hours