In BASIC:
10 INPUT X: IF X = 999 THEN STOP ELSE PRINT X;
20 IF X/2 = INT(X/2) THEN PRINT "EVEN" ELSE PRINT "ODD"
30 GOTO 10
Chat with our AI personalities
The number 170 is even.
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
If you add, subtract, or multiply two even numbers, you will get an even number. If you divide an even number by another even number, you may get an even number, an odd number, or even a fraction.
The pseudo code would be as follows (you figure out the syntax) 1) Prompt the user to enter a number 2) If entered number is alpha, quit program after displaying message that the user ended the program. 3) Otherwise, find Modulo 2 of the entered number. This is a fancy way of saying "find the remainder when the number is divided by 2) 4) If Modulo 2 is zero, the number is even, otherwise odd 5) Display message showing if the entered number was Even or Odd 6) Branch back to step 1
int main () { int x; printf ("Enter the value of x\n"); scanf ("%d",&x); if (0 == x%2) printf ("Number is even\n") else printf ("Number is odd\n"); }