This function is suppose to return the number of odd and even values in a vector
ID: 3545766 • Letter: T
Question
This function is suppose to return the number of odd and even values in a vector. Correct the function. (Values cannot be returned through any vector or array or structure. Must be only one function to get both the number of odd and even values.)
int numOfOddEven( vector[int] intVec )
{
int odd, even;
for ( i = 0; i <= vecSize; ++i )
if ( i / 2 == 1 )
++even;
else
++odd;
return odd;
return even;
}
Explanation / Answer
int numOfOddEven( vector[int] intVec )
{
int odd=0;
for ( i = 0; i <= vecSize; ++i )
{
if ( i % 2 == 1 )
++odd;
}
return odd;
}
thus we get the number of odd numbers in the array.
the number of evens can be found easily by (vecSize-odd)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.