If Statement - C Tutorial

If Statement

If statements in C is used to control the program flow based on some condition, it’s used to execute some statement code block if expression is evaluated to true, otherwise it will get skipped.

Syntax of if statement

 if(boolean_expression)
    statement;

What is a Boolean expression?

A C expression that evaluates either true or false is known as Boolean expression. However, in C programming there is no concept of true or false value.

In C we represent true with a non-zero integer and false with zero. Hence, in C if an expression evaluates to integer is considered as Boolean expression.

Block of Statement in if

if(boolean_expression)
{
    statement 1;
    statement 2;
    ...
}

C Program to Check Whether a Number is Even or Odd using If

#include<stdio.h>
int main()
{
	int num;
	printf("Enter the Number :");
	scanf("%d",&num);
	if(num%2==0)
		printf("%d is Even Number",num);
	if(num%2!=0)
		printf("%d is Odd Number",num);
	return 0;
}
Output - C Program to Check Whether a Number is Even or Odd using If
Enter the Number :13                                                                                                  
13 is Odd Number