if..else Statement

if else statement

if..else Statement in C

The if statement followed by an optional else statement, which executes when the conditional expression is false.

If the conditional expression evaluates to true, statements of if block are executed and statements of else block are skipped.

If the conditional evaluates to false, statements of else block are executed and statements of if block are skipped.

Syntax

        
if (test expression) 
{
    // run code if conditional expression is true
}
else 
{
    // run code if conditional expression is false
}      
        
    

Program

        
#include <stdio.h>

int main ()
{
    int number = 5;

    // True if the remainder is 0
    if  (number %2 == 0) 
    {
        printf("%d is an even integer.", number);
    }
    else {
        printf("%d is an odd integer.", number);
    }
    return 0;
}             
        
    

Output

        
5 is an odd integer.             
        
    



Join Our Social Media Connections

Post a Comment

0 Comments