The `if` statement is used when an operation should be performed only when a specified condition is satisfied.
#include <stdio.h>
#include <conio.h>
int main()
{
int number1, number2;
printf("Enter two numbers:\n");
scanf("%d %d", &number1, &number2);
if ( number1 == number2 )
printf("%d is equal to %d\n", number1, number2);
if ( number1 != number2 )
printf("%d is not equal to %d\n", number1, number2);
if ( number1 < number2 )
printf("%d is less than %d\n", number1, number2);
if ( number1 > number2 )
printf("%d is greater than %d\n", number1, number2)
if ( number1 <= number2 )
printf("%d is less than or equal to %d\n", number1, number2);
if ( number1 >= number2 )
printf("%d is greater than or equal to %d\n", number1, number2);
if ( number1 % 2 == 0)
printf("number1 is even");
else
printf("number1 is odd");
getch();
return 0;
}
The conditions use parentheses and compare two variables with the comparison operators `==`, `!=`, `<`, `>`, `<=` and `>=`.
There are two possible outcomes. When the condition is true, the statement after `if` is executed; otherwise it is skipped. For a single statement this continues up to the terminating semicolon. Multiple statements must be placed between braces `{` and `}`.
The percent sign (`%`) performs the modulo operation. If the result is zero, the number is evenly divisible. In this example, a true condition prints that `number1` is even.