C

if...else statement

Syntax:

The general form of a simple if...else statement is,

if(expression)
{
    statement-block1;
}
else
{
    statement-block2;
}

If the 'expression' is true, the 'statement-block1' is executed, else 'statement-block2' is executed.

Example:

//Write a C Program which demonstrate use of if else-statement.
#include<stdio.h>
#include<conio.h>
void main()
{
    int x,y;
    x = 5;
    y = 7;
    if (x > y)
    {
        printf("x is greater than y");
    }
    else
    {
        printf("y is greater than x");
    }
    getch();
}

Output:

Command Prompt
y is greater than x



Subscribe us on Youtube

Share This Page on


Ask Question