#include <stdio.h>
int main()
{
int x;
printf("Input x: "); scanf("%d", &x);
if ((x > 0) && (x % 2 == 0))
printf("x is both positive and even.\n");
else
printf("Invalid values of x detected!\n");
return 0;
}
This example illustrates on how we combine conditions. Notice the brackets. Enclosing
conditions in brackets are not necessary, but sometimes will help compiler (so that it won't
warn you) and improve readability.
Try running this example a few times each with the following input respectively:
-2, -1, 0, 1, and 2.
Their respective output was:
Invalid values of x detected!
Invalid values of x detected!
Invalid values of x detected!
Invalid values of x detected!
x is both positive and even.