Create a c++ program the counts and display the odd and even numbers among the ten input values using a two dimensional array.
First row - 10 input numbers
Second row - even numbers
Third row - odd numbers
#include<iostream>
using namespace std;
int main()
{
int eve = 0, odd = 0, i = 0, j = 0, k = 0;
int arr[3][10];
cout<<"Enter 10 Array Elements:\n";
for(i=0; i<10; i++)
cin>>arr[0][i];
for(i = 0; i < 10; i++){
if(arr[0][i] % 2 == 0){
eve++;
arr[1][j] = arr[0][i];
j++;
}
else{
odd++;
arr[2][k] = arr[0][i];
k++;
}
}
cout << "\nTotal Number of Even Numbers = " << eve;
cout << "\nTotal Number of Odd Numbers = " << odd << endl;
for (int n = 0; n < 3; n++){
if (n == 0){
for(i = 0; i < 10; i++)
cout << arr[n][i] << " ";
cout << endl;
}
if (n == 1){
for(j = 0; j < eve; j++)
cout << arr[n][j] << " ";
cout << endl;
}
if (n == 2){
for(k = 0; k < odd; k++)
cout << arr[n][k] << " ";
cout << endl;
}
}
return 0;
}
Comments
Leave a comment