Conditional Statements in C ( if…else)

Conditional Statements in C ( if…else)



else if condition
'else if' is keyword in java language which is used to execute one block of statemnets amoung the multiple blocks.
Syntax:
if(Condition)
{
    statement 1
    statement 2
    ..
    ..
}
else if(condition)
{
    statement 3
    statement 4
    ..
    ..
}
else if(condition)
{
    statement 5
    statement 6
    ..
    ..
}
..
..
else
{
    statement 7
    statement 8
    ..
    ..
}



Age Program
0-12 child age
12-19 teen age
19-40 younger age
40-80 old age
80-100 too old age
above 100 invalid
-11 negative age

#include <stdio.h>
                                                                         
int main() {
    int age;
    printf("Enter Your Age");
    scanf("%d",&age);
    if(age>0 && age<=12)
    {
        printf("You are a child");
    }
    else if(age>12 && age<=19)
    {
        printf("You are a teenager");
    }
    else if(age>19 && age<=40)
    {
        printf("You are younger");
    }
    else if(age>40 && age<=80)
    {
        printf("You are old");
    }
    else if(age>8 && age<=100)
    {
        printf("You are too old");
    }
    else if(age>100)
    {
        printf("Invalid");
    }
    else
    {
     printf("Age should not be negative");
    }
    
    return 0;
}
                                            

Output:

Enter Your Age 24
You are younger

Enter Your Age 10
You are a child

Enter Your Age -24
Age should not be negative


More Programs


Write a C-program to print max number among three numbers