Conditional Statements in C (nested if…else)

Conditional Statements in C (nested if…else)



Nested if Condition
One if condition with in another if condition is known as nested if.
Syntax:
if(Condition)
{
    if(condition)
    {
        statement 1
        statement 2
    }
    else
    {
        statement 3
        statement 4
    }
}
else
{
    statement 5
    statement 6
}



ODD or Even Number Program Using IF ELSE Condition(Value Must Be Positive)

#include <stdio.h>
                                                                         
int main() {
    int x;
    printf("Enter x value ");
    scanf("%d",&x);
    if(x>0)
    {
       if(x%2==0)
       {
            printf("%d is Even Number",x);
       }
       else
       {
          printf("%d is Odd Number %d",x); 
       }
    }
    else
    {
         printf("Please Enter Positive Number");
    }
    
    return 0;
}
                                            

Output:

Enter x value 10
10 is Even Number

Enter x value 11
11 is Odd Number

Enter x value -24
Please Enter Positive Number


More Programs


Write a C-program to print 10 to 1 values using for loop