Introduction Data type Variable-Constant Keyword-Identifier Operations Input&Output If-else Switch loops String Array Functions Recursion-Function Mat-Function Pointers File handling Read & write Error handling Read & write error handling


If..Else
if

The if statement is a powerful decision making statement, if it is condition true executes the given block of codes


  if(condition){
    // statements of code 
   }
            

Input
 #include <stdio.h>

   int main() {
           
      int age;
      age=23;
      if(age>21){
         printf(" Your age is greater than 21");    
              } 
       return 0;
        }     

OutPut
Your age is greater than 21

Note :- in this condition suppose age lesser then 21 means the condition not satisfy .

else

else is used to executes, if the first condition is false / if all condition not satisfied then else block statements executes defaultly.


    if(condition1){
        //statements1
    }
    else{
        //default statement   
    }
    


Example
  #include <stdio.h>
    int main() {
     int age;
     age=23;
     int age1=21;
    //Taking decision 
     if(age < age1){
         printf("The age is greater then 23");
                  }
     else{
         printf("The age is lesser then 23");
        }
    }
        

OutPut
The age is lesser then 23
else if

Used to checking / testing different conditions one by one.

Like if the first condition is false , then check the secend condition until satisfing condition if not found in any condition then else block statements executes defaultly


Example
#include <stdio.h>
   int main() {
     int age;
     age=23;
     int age1=21;
     if(age ==age1){
           printf("age is qual to the 21");
                   }
     else if(age < age1){
           printf("The age is lesser then 23");
                        }
     else{
 // output is Not found because anycondition is not satisfied
        printf("Not found "); 
           }
              }
    

OutPut
Not found

Open kannada !





@2022, Padma Education.

We cannot warrant full correctness of all content, we try to give our best. While using Padma education website, you agree to have read and accepted our terms and Conditions , privacy policy.