An array is special, if it contains equal number of even and odd numbers. Create a PROGRAM that print true if an array is special, and false otherwise.
#include<iostream>
using namespace std;
int checkArray(int arr[], int size){
int odd= 0;
int even = 0;
for(int i = 0; i<size; i++){
if(arr[i] % 2 == 0 ){
even ++;
}
else{
odd++;
}
}
if(odd==even){
return 1;
}
else{
return 0;
}
}
int main(){
int arr[] = { 2, 3, 4, 5, 6,1 };
if(checkArray(arr, 6)==1){
cout<<"True\n";
}
else{
cout<<"False\n";
}
}
Comments
Leave a comment