0
Pls someone should help
Write a C++ program to tell a user to input a non-negative integer and check if the number is even. If it is even, print "the number is even", if it is odd, print "the number is odd". If the number is even, print the even number from the "user input" down to 1.
2 Antworten
0
Try this
#include <iostream>
using namespace std;
int main() {
// prompt the user to input a non-negative integer
int num;
cout << "Enter a non-negative integer: ";
cin >> num;
// check if the number is even or odd
if (num % 2 == 0) {
cout << "The number is even." << endl;
// print the even numbers from the user input down to 1
for (int i = num; i >= 1; i -= 2) {
cout << i << " ";
}
} else {
cout << "The number is odd." << endl;
}
return 0;
}