Answer:
The solution code is written in Python
- numList = [10, 20, 30, 40]
-
- for i in range(0, len(numList) - 1):
- numList[i] = numList[i] + numList[i + 1]
-
- print(numList)
Step-by-step explanation:
Firstly, create a sample number list, numList (Line 1)
Create a for-loop that will traverse through the array element from 0 till the second last of the element (len(numList) - 1) (Line 3)
Set the current element, numList[i], to the sum of the current element, numList[i] and the next element, numList[i+1]
Print the modified numList (Line 6) and we can see the output as follows:
[30, 50, 70, 40]