Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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)


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote