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; }
1 Resposta
+ 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.