[C++] Determine whether all the data meet the conditions

Judge whether all the elements of an array are odd, and return true if all are satisfied

#include<iostream>
using namespace std;
int main() {
    
    
	int num[] = {
    
     1,3,5,6,7,9 };
	bool flag = true;
	for (int i = 0; i < 6; i++) {
    
    
		if (num[i] % 2 != 1) {
    
    
			flag = false;
			break;
		}
	}
	cout << flag;
	return 0;
}

Determine whether the data meets the requirements

Guess you like

Origin blog.csdn.net/weixin_48180029/article/details/115149103