Question

In: Computer Science

C++ 1) Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write...

C++

1) 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.

2) 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.

Solutions

Expert Solution

#include<bits/stdc++.h>
using namespace std;

int main(){
  int n; // total number of elements in the array
  cin >> n;
  int arr[n]; //defining array of size n
  int oddCount = 0, evenCount = 0;
  for(int i = 0; i<n; i++){
    cin >> arr[i];
    if(arr[i]%2 == 0) // checking if number is even
    {
      evenCount = evenCount +1; //increasing even count
    }
    else{ // checking for odd numbers
      oddCount = oddCount + 1; // increasing odd count
    }
  }
  cout << "Total number of even numbers are " << evenCount << " and total number of odd numbers are " << oddCount << endl;
  int even[evenCount]; // array of even numbers only
  int odd[oddCount];  // array of odd numbers only
  //Question two starts from here
  
  int j = 0, k = 0; // iterators 
  for(int i = 0; i < n; i++){
    if(arr[i]%2 == 0) // checking if number is even
    {
      even[j++] = arr[i]; // storing even numbers in even array
    }
    else{ // checking for odd numbers
      odd[k++] = arr[i]; // storing odd numbers in odd array
    }
  }
  cout << "Even numbers array : ";
  for(int i = 0 ; i<evenCount; i++){ // dispalying even numbers array
    cout << even[i] << " ";
  }
  cout << "\nOdd numbers array : ";
  for(int  i = 0; i<oddCount; i++){ //displaying odd numbers array
    cout << odd[i] << " ";
  }
}

output will look like below image

i have done both questions combined and added comments for better understanding. i hope it will help you.

for any more doubt comment below.


Related Solutions

Elements 1-7 for Sample 1 are 11 7 9 12 13 15 15. Elements 1-7 for...
Elements 1-7 for Sample 1 are 11 7 9 12 13 15 15. Elements 1-7 for Sample 2 are 8 8 6 7 10 15 14.Construct a 95% conf.interval for the mean of the paired sample differences.
Periods ​1% ​2% ​3% ​4% ​5% ​6% ​7% ​8% ​9% ​10% ​12% ​14% ​15% ​16% ​18%...
Periods ​1% ​2% ​3% ​4% ​5% ​6% ​7% ​8% ​9% ​10% ​12% ​14% ​15% ​16% ​18% ​20% 1 0.990 0.980 0.971 0.962 0.952 0.943 0.935 0.926 0.917 0.909 0.893 0.877 0.870 0.862 0.847 0.833 2 0.980 0.961 0.943 0.925 0.907 0.890 0.873 0.857 0.842 0.826 0.797 0.769 0.756 0.743 0.718 0.694 3 0.971 0.942 0.915 0.889 0.864 0.840 0.816 0.794 0.772 0.751 0.712 0.675 0.658 0.641 0.609 0.579 4 0.961 0.924 0.888 0.855 0.823 0.792 0.763 0.735 0.708 0.683 0.636...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
Day 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Number of Aides Absent 5 8 11 15 4 2 7 1 4 6 14 19 3 5 8 In which of the following ranges you can find the Upper Control Limit of the control chart? 0.1427 0.1536 0.1677 Not computable with information available In which of the following ranges you can find the Lower Control Limit of the control chart? Does not exit...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...
student 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Test score 67 67 87 89 87 77 73 74 68 72 58 98 98 70 77 Above we have the final averages of the last stats and I want to know if the class average falls within the boundaries of all my statistics classes for the past 20 years. Find the sample size, mean, and standard deviation of the data above (Table 1)....
11 12 11 10 14 15 16 12 11 10 12 20 13 32 35 14...
11 12 11 10 14 15 16 12 11 10 12 20 13 32 35 14 41 12 10 11 12 12 13 16 14 17 18 19 12 13 14 10 10 14 11 10 12 14 12 13 16 14 17 19 20 15 25 15 45 45 44 41 40 14 18 19 24 20 26 36 34 30 31 50 15 12 Find the following: Mean? (1) Median (2), and Mode? Find : Q3, Q1, D7,...
Promotional expenses(x) Sales(y 7 12 10 14 9 13 4 5 11 15 5 7 3...
Promotional expenses(x) Sales(y 7 12 10 14 9 13 4 5 11 15 5 7 3 4 a) draw the scatter plot and draw the line of best fit b) Calculate and interpret the correlation between promotional expenses and sales C) Calculate the regression equation( calculate the slope and intercept of the regression line d)Interpret the slop coefficient of regression equation e)Using the regression equation calculate the sales volume with respect to promotional expense of 4. f) Obtain the coefficient...
Using the following data set: 10, 5, 2, 7, 20, 3, 13, 15, 8, 9 Apply...
Using the following data set: 10, 5, 2, 7, 20, 3, 13, 15, 8, 9 Apply the Merge sort algorithm. [Show to sorting process of the first half only] Apply the Quick sort algorithm [Show the first partitioning implementation]
5.) For the data set 2 4 4 5 7 8 9 10 12 12 13...
5.) For the data set 2 4 4 5 7 8 9 10 12 12 13 13 16 16 16 16 17 19 19 20 23 24 24 24 25 26 26 27 28 28 29 31 32 34 34 36 37 38 42 44 45 46 47 47 48 50 52 53 53 54 55 56 56 57 58 (a) Find the 80th percentile. The 80t percentile is =    (a) Find the 42nd percentile. The 42nd percentile is...
Estriol - X Birthweight -y 7 25 9 25 9 25 12 27 14 27 16...
Estriol - X Birthweight -y 7 25 9 25 9 25 12 27 14 27 16 27 16 24 14 30 16 30 16 31 17 30 19 31 21 30 24 28 15 32 16 32 17 32 25 32 27 34 15 34 15 34 15 35 16 35 19 34 18 35 17 36 18 37 20 38 22 40 25 39 24 43 The table shown above is taken from the Greene-Touchstone study which shows the...
Treatments A B C D -5 -9 -15 -20 -4 -4 -18 -9 -5 -16 -8...
Treatments A B C D -5 -9 -15 -20 -4 -4 -18 -9 -5 -16 -8 -20 -15 -4 -18 I do not understand how to calculate the SSE for statistics. I was able to get the SSTR and MSTR but I just don't understand how to get the SSE from this info.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT