Question

Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write a program...

Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27}

Write a program to construct array ODD[] and EVEN[] from Arr[10] as you realize ODD[] consists of odd number and EVEN[] consists of even number.

for c++

Homework Answers

Answer #1

Ans:-

Code:-

#include <iostream>
using namespace std;

int main() {
        //intialize given array
        int Arr[]= {7, 9, 13, 15, 16, 10, 12, 5, 20, 27},o=0,e=0;
        // loop to find the number of even and odd number in the given array
        cout<<"The given array is: ";
        for(int i=0;i<10;i++)
        {
            cout<<Arr[i]<<" ";
            if(Arr[i]%2 == 0)
                e++; // if the element is even, then update the count of e
            else
                o++; // if the element is odd, then update the count of o
        }   
        int ODD[o], EVEN[e]; //declare two array ODD and EVEN of size o and e respectively
        //update the value of e and o to zero in order to track the index of EVEN and ODD ARRAY respectively
        e=0; 
        o=0;
        for(int i=0;i<10;i++)
        {
            if(Arr[i]%2 == 0) // if the element is even, then store it into EVEN array
                EVEN[e++] = Arr[i];
            else    // if the element is odd, then store it into ODD array
                ODD[o++] = Arr[i];
        }
        cout<<"\nEVEN ARRAY IS: ";
        //Print the even ARRAY
        for(int i=0;i<e;i++)
            cout<<EVEN[i]<<" ";
        //Print the ODD array
        cout<<"\nODD ARRAY IS: ";
        for(int i=0;i<o;i++)
            cout<<ODD[i]<<" ";
        return 0;
}

Output:-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write a program...
Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write a program to count number of EVEN and ODD items. Do a screen output of your result. for c++ please
y 10 11 15 15 20 24 27 32 x1 2 5 5 9 7 11...
y 10 11 15 15 20 24 27 32 x1 2 5 5 9 7 11 16 22 x2 16 10 13 10 2 8 7 4 a) Construct a​ 95% confidence interval for the dependent variable when x1=7 and x2=11. The​ 95% confidence interval is from a lower limit of ___ to an upper limit of ___. b) Construct a​ 95% prediction interval for the dependent variable when x1=7 and x2=11. The​ 95% prediction interval is from a lower...
13, 16, 7, 8, 10, 19, 15, 16, 13, 15 ,8 ,5 ,12, 17, 10, 0,...
13, 16, 7, 8, 10, 19, 15, 16, 13, 15 ,8 ,5 ,12, 17, 10, 0, 3, 14, 12, 2 The data represent the​ time, in​ minutes, spent reading a political blog in a day. Construct a frequency distribution using 5 classes. In the​ table, include the​ midpoints, relative​ frequencies, and cumulative frequencies. Which class has the greatest frequency and which has the least​ frequency?
Given ID X Y A 10 15 B 4 5 C 13 16 D 7 9...
Given ID X Y A 10 15 B 4 5 C 13 16 D 7 9 E 13 4 F 1 5 What is the variation in Y that can be explained by X? please explain A) 50.7 B) 22.7 C) 36.3 D) 105.7 E) 91.3
A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14...
A = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20] In MATLAB. Use a fully vectorized code (ie. no loops) to determine when the numbers have increased to at least 15 in the above array. Report answer to command window.
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...
Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...
Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1,...
Given this array: int sequence[10] = { 3, 4, 5, 6, 7, 8, 9, 10, 1, 2 }; Write a C++ program to ask the user to enter a number, if the number can be found in the array, your program should display "Found". Otherwise, your program should display "Not found". For example, if the user enters 7, your program should display "Found". If the user enters 11, your program should display "Not found".
Dep Delay Arr Delay q1 -13 -9 q3 1 3 IQR 14 12 stdev 9.211846 9.660933...
Dep Delay Arr Delay q1 -13 -9 q3 1 3 IQR 14 12 stdev 9.211846 9.660933 negative 291 zero 39 positive 170 total (should be 500) 500 all data is for arrival data. please help me explain these can someone help me answer these questions and tell me how to put them in excel.thanx in advance 1.    Define a random variable (X) so that your chosen data set represents values of X. 2.    Is your chosen random variable discrete or...
Lessons Frequency 10-12 5 13-15 9 16-18 12 19-21 4 22-24 10 The mean for that...
Lessons Frequency 10-12 5 13-15 9 16-18 12 19-21 4 22-24 10 The mean for that distribution is: - 19.11 - 18.22 - 17.38 - 16.15 The mode of this distribution is: -23 -15 -17 -12
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT