Ask 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 next element, except for the last element which stays the same. be careful not to index beyond the last element.

+1
Answers (1)
  1. 5 June, 05:07
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers