Respuesta :
Answer:
The C program is commented in the explanation
Explanation:
I am going to write a C program, a function that receives an array and the array length.
I can update each position with a for loop. This loop is going to end at the next to lastPosition(so, i < n-1);
void sum(int * bonusScores, int n){
int i;
for(i = 0; i < n-1; i++){
bonusScores[i] = bonusScores[i] + bonusScores[i+1]
}
}
This should do it :)
Answer:
#Python
1. bonusScores = [10, 20, 30, 40]
2. print("Before",bonusScores)
3. for i in range(len(bonusScores)-1):
4. bonusScores[i] = bonusScores[i] + bonusScores[i+1]
5. print("After",bonusScores)
Explanation:
- On the first line, we define our array bonusScores
- On line two we print how this array looks like before making any changes
- On line 3 we create a for loop to iterate over the length of the array omitting the last element (len(bonusScores)-1)
- On line four we sum the current element with the next one
- On line five we print the final result
