Write a for loop that sets each array element in bonusScores to the sum of itsel
ID: 3837286 • Letter: W
Question
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.
Ex: If bonusScores = [10, 20, 30, 40], then after the the loop bonusScores = [30, 50, 70, 40]
The first element is 30 or 10 + 20, the second element is 50 or 20 + 30, and the third element is 70 or 30 + 40. The last element remains the same.
the answer has to come out [30, 50, 70, 40]
Your Function Save C Reset BE MATLAB Documentation 1 function bonusScores Combine Scores (numberscores user Scores) 2 number Scores: Number of scores in array bonusScores 3 bonusScores: User defined array of test scores 96 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 bonus Scores user Scores 10 end Code to call your function C Reset 1 Combine Scores (4, [10, 20, 30, 401)Explanation / Answer
Answer:
function bonusScores = CombineScores(numberScores, userScores)
bonusScores= userScores
for i = 0:numberScores-1
bonusScores(i) = sum(userScores(i) , userScores(i+1));
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.