C-if-statement .

In this session i have discussed if statement in C .


If statement is a decision making and branching statement in C . It is following types .

IF statement .

IF-Else statement .

Else-IF Ladder statement .

Nested IF-Else .


IF-Statement :

If statment is a powerful decision making and branching statment . It is allow to evaluate the specified condition if condition is true then the statement inside the if will be executed other wise control transfer to next statement .

If-statement-syntax :

mvc image

Example : Write a program check the age for voting .

    #includ<stdio.h> 
    int main()
    {
         int age=19;
         if(age>17)
         {
              printf("Valid for vote");
         }
         printf("\nThanks");
         return 0;
    }
    
    OUTPUT : Valid for vote
             Thanks
    


Example : Write a program check the even number .

    #includ<stdio.h> 
    int main()
    {
            int x=4;
            if(x%2==0)
            {
                printf("Even Number");
            }
            printf("\nThanks");
            return 0;
    }
    
    OUTPUT : Even Number
             Thanks
    


Example : Write a program check the odd number .

    #includ<stdio.h> 
    int main()
    {
            int x=5;
            if(x%2!=0)
            {
                printf("Odd Number");
            }
            return 0;
    }
    
   OUTPUT : Odd Number
   

Welcome to AndroidATPoint.

back image                     next image