#include <iostream>
int main()
{
int num;
std::cout << "Enter a number: ";
std::cin >> num;
if(num % 2 == 0)
{
std::cout << "Number is even";
}
else
{
std::cout << "Number is odd";
}
return 0;
}
Chat with our AI personalities
For any number n you could use * (n % 2 == 0), which would be true for an even number, false for odd For an integer i, a simpler method would be * (i & 1), which would be true for an odd number, false for even
odd loop means at least the loop execute once.
By learning how to program on C+.
int i, sum = 0; for (i=0; i<20; i+=2) sum+=i;
Even (unless c = 0 in which case it is either or both!)