Answer to Question #242389 in C++ for MSK

Question #242389

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.


1
Expert's answer
2021-09-26T11:42:27-0400
#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";
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS