Write a program that will get the sum of even indexed elements and the sum of odd indexed elements? |
[Edit] |
In order to write a program, we have to have an algorithm. In this case, we can use two temporary variables to store up the sums:
evenSum = 0
oddSum = 0
for i = 0 to array.size do:
if isEven(i):evenSum = evenSum + array[i]else:
oddSum = oddSum + array[i]
First answer by Avir. Last edit by Avir. Contributor trust: 56 [recommend contributor]. Question popularity: 9 [recommend question]
|
Research your answer: |
Can you answer other
questions about programming?



