Write a loop that reads positive integers from standard input, printing out those values that are even, separating them with spaces, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

Write a loop that reads positive integers from standard input, printing out those values that are even, separating them with spaces, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

LANGUAGE: C++

CHALLENGE:

Write a loop that reads positive integers from standard input, printing out those values that are even, separating them with spaces, and that terminates when it reads an integer that is not positive. Declare any variables that are needed.

SOLUTION:


int num=1;
while (num>0){
    	cin >> num;
    	if ((num % 2) == 0 && num > 0 ){
        	cout << num << " ";
	    }
}

Add comment