A Program to Check Whether a Number is Even or Odd

In this example, we are giving a program which is useful to check whether a number given by the user is even or odd.


Program to check even or odd:

  1. #include <stdio.h>
  2. int main()
  3. {
  4. int number;
  5. printf("Enter an integer: ");
  6. scanf("%d", &number);
  7. // True if the number is divisible by 2
  8. if(number % 2 == 0)
  9. printf("%d is even.", number);
  10. else
  11. printf("%d is odd.", number);
  12. return 0;
  13. }

Output:

Enter an integer number: -53
-53 is odd.