Ask Question
21 June, 02:28

Modify an array's elements using other elements write a for loop that sets each array element in bonusscores to the sum of itself and the next element, except for the last element which stays the same. be careful not to index beyond the last element.

+4
Answers (1)
  1. 21 June, 04:23
    0
    Assuming that the language is C + + and that the following variables exist: bonusscores is an array of some numeric type (float, double, int, etc). nent is an integer indicating how many elements are in bonusscores. Also assuming that the array is 0 based, so legal subscripts range from 0 to nent-1. / / Code starts here for (int x = 0; x < (nent-1); + + x) { bonusscores[x] = bonusscores[x] + bonusscores[x+1]; } / / Code ends here Thing to note, since the last element isn't modified, the range for the for loop is reduced by 1 so that every element to actually be modified is visited, but the last element isn't. And since each element after modification isn't needed for future modifications, it's safe to change them in situ.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Modify an array's elements using other elements write a for loop that sets each array element in bonusscores to the sum of itself and the ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers