If Else control statement

If Else statement

It is the way to talk with our program by if or else statement by, like some specific set of instructions will be execute when the true condition will meet.
    If the condition is true then it will execute otherwise it will execute the else if statement or else statement in the program.

Types of statements:
    1> if statement
    2> If else statement
    3> If -else if ladder
    4> Nested if

Flowchart for if statement

code for if👇

#include <stdio.h>

int main(int argcchar const *argv[])
{
    int age;
    printf("Enter your age\n");
    scanf("%d", &age);

    printf("You entered %d as your age\n"age);
    if (age>18)
    {
        printf("you can vote");
    } 
    return 0;
}

Flowchart for if- else statement

code for if👇

#include <stdio.h>

int main(int argcchar const *argv[])
{
    int age;
    printf("Enter your age\n");
    scanf("%d", &age);

    printf("You entered %d as your age\n"age);

    if (age>18)
    {
        printf("you can vote");
    }

    else
    {
        printf("you can't vote.");
    }  
    return 0;
}

Flowchart for if- else if ladder statement

code for if👇

#include <stdio.h>

int main(int argcchar const *argv[])
{
    int age;
    printf("Enter your age\n");
    scanf("%d", &age);

    printf("You entered %d your age\n"age);

    if (age >= 18)
    {
        printf("you can vote");
    }

    else if (age >= 10)
    {
        printf("you are between 10 to 18, you can vote for the kids");
    }

    else
    {
        printf("you can't vote.");
    } 
    return 0;
}

In if else statement there is only one statement can print at a time, Hence the statement can't print one or more for a single condition, the condition must be true or false.

Comments

Popular Posts