Ask Question
28 February, 08:54

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. 28 February, 09:59
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers