0

function that returns the sum of the odd numbers

#include <iostream> using namespace std; int main(){ int i = 0; int v[6] = {4,1,6,8,3,5}; if(v[6] > 0) { i++; } cout << i; }

22nd Apr 2020, 12:37 PM
KeynerZzz
KeynerZzz - avatar
1 Respuesta
+ 7
KeynerZzz According to your attempt, you're not even iterating over the array. The only thing you're doing is ... you're checking to see if the seventh element of the array (which doesn't exist, btw) is greater than zero, before incrementing i to 1 and outputting 1. Things to remember: • Arrays start from 0, not 1. • A simple way to address all elements of an array, list, and/or vector is to iterate over the elements via a (for, while, do, etc.) loop.
23rd Apr 2020, 6:40 PM
Fox
Fox - avatar