What type of iteration would be appropriate for calculating the sum of the first 100 positive integers? What type would be appropriate for calculating 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 repetitions is known in advance. The program that performs this task could use a while iteration statement with a counter variable that takes on the values 1 to 100. The program could then add the current counter value to the total variable in each repetition of the loop. Sentinel-controlled iteration would be appropriate for calculating the sum of an arbitrary number of positive integers. The program that performs this task could use a sentinel value of –1 to mark the end of data entry. The program 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...
________ is a system tool that clears the hard drive of all unwanted files such as temporary Internet files or files in the Recycle Bin
Fill in the blank(s) with correct word
After opening a database, the Navigation Pane opens on the left side of the screen.
Answer the following statement true (T) or false (F)