What type of iteration would be appropriate for calculating the sum of the first 100 positive integers? What type of iteration would be appropriate for calculat- ing the sum of an arbitrary number of positive integers? Briefly describe how each of these tasks could be performed.
What will be an ideal response?
Counter-controlled iteration would be appropriate for calculating the sum of the first
100 positive integers, because the number of iterations is known in advance. The application that performs this task could use a while iteration statement with a counter variable that takes on the values 1 to 100. The application could then add the current counter value to the total variable in each iteration of the loop. Sentinel-controlled iteration would be appropriate for calculating the sum of an arbitrary number of positive integers. The application that performs this task could use a sentinel value of –1 to mark the end of data entry. The application could use a while iteration statement that totals positive integers from the user until the user enters the sentinel value.
You might also like to view...
How many constructors does the Picture class have?
What will be an ideal response?
In addition to the preset gradients that come with Photoshop, you can create your own customized gradients in the Gradient Editor dialog box.
Answer the following statement true (T) or false (F)