If-Else Statement|Conditional Operations in C Language

Conditional Statements Operations in C Language

Simple if statement in C Language

If Statement: If the condition is true its body executes otherwise does not execute. In the case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition is true.

C, the if statement is used to conditionally execute a block of code based on the value of a given expression. 

If-Else Statement|Conditional Operations in C Language
If-Else Statement|Conditional Operations in C Language

    if statement syntax in C Language

    if(condition)

    {

    //Statements;

    }


    What is if statement in C with example?

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int x=50;

    int y=20;

    if(x>y)

    {

    printf("x is greater than y");

    }

    getch();

    }


    **********OUTPUT**********

    x is greater than y

    Choose a statement to use if else statement in C Language

    If-Else Statement:  C the if-else statement is an extension of the if statement that allows you to specify an alternative block of code to be executed if the condition in the if statement is not met.
    if the condition is true if part executes and if the condition is false else part executes.
    In the case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition true.

    Syntax of if-else statement in C Language

    if(condition)

    {

    //Statements;

    }

    else

    {

    //Statements;

    }


    What is if else statement explain with example

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int x=50;

    int y=20;

    if(x==y)

    {

    printf("x is greater than y");

    }

    else

    {

    printf("x is not greater than y");

    }

    getch();

    }


    **********OUTPUT**********

    x is not greater than y


    Explain if else if ladder statement with syntax and example

    If-Else Ladder Statement: It is part of a conditional statement that executes only one condition at a time. If all conditions are false then else part executes.It executes that condition that becomes first true from the top. In case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition are true.  

    Syntax of if-else Ladder statement in C Language

    if(condition)

    {

    //Statements1;

    }

    else if(condition)

    {

    //Statements2;

    }

    else if(condition)

    {

    //Statements3;

    }

    else()

    {

    //Statements4;

    }

     
    What is if else if ladder explain with an example

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int x=10;

    if(x>5)

    {

    printf("x is greater than 5");

    }

    else if(x<8)

    {

    printf("x is less than 8");

    }

    else if(x==10)

    {

    printf("x is equal o 10");

    }

    else

    {

    printf("No one condition is true");

    }

    getch();

    }


    **********OUTPUT**********

    x is greater than 5


    Nested if statement in C Language with example

    Nested If Statement: Nested means one inside another so one if inside another if is called nested if. In the case of if in the place of condition always zero and non-zero value is checked in which zero means condition false and non-zero means condition true.

    Syntax of Nested if statement in C Language

    if(condition)

    {


      if(condition)

    {

    //Statements1;

    }

    }


    What is Nested if statement explain with example

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int x=50;

    if(x>5)

    {

    if(x<15)

    {

    printf("x is greater than 5 and less than 15");

    }

    }

    getch();

    }


    **********OUTPUT**********

    x is greater than 5 and less than 15


    Switch Statement in C Programming Language

    Switch Statement: Switch statement allows us to execute one statement from many statement and that statements are called case.
    Actually in switch statement inside the body of switch a number of cases are used and from which case this parameter is matched executed.
    In the switch statement a value number is passed in the place of parameter and that case will execute which is equal to that value/number. If Number case matched with parameter then default case will be executed.

    Switch case syntax and example in C

    switch(condition)

    {

    case 1:

    statement1;

    break;


    case 2:

    statement2;

    break;


    case 3:

    statement3;

    break;


    case n:

    statement n;

    break;

    default:

    default statement;

    }


    Explain switch case statement with example in C

    #include<stdio.h>

    #include<conio.h>

    void main()

    {

    int s=2;

    switch(2)

    {

     case 1:

    printf("Case 1 will be executed");

    break;

    case 2:

    printf("Case 2 will be executed");

    break;

    case 3:

    printf("Case 3 will be executed");

    break;

    default:

    printf("Case are not match");

    }

    getch();

    }


    **********OUTPUT**********

    Case 2 will be executed


    Post a Comment

    0 Comments