If-Else Statement

If Else Statement is always return ture or false.If it returns true then it excute if() part otherwise it excute the else part.We can divide the if-else statement in three parts.

  1. Genaral If-else Statement
  2. Else if Statement
  3. Nasted if-else statement


Genaral If-else Statement: flowchart example
example1:
#include<stdio.h>
int main(){
  int a=5, b=3;
  if(a>b){//becomes ture
    printf("a is grater then b");
  }
  else{ 
    printf("b is grater then a");
  }
   return 0;
}

Output:
    a is grater then b

example2:
  #include<stdio.h>
  int main(){
    int a=2, b=3;
    if(a>b){//becomes false
      printf("a is grater then b");
    }
    else{
      printf("b is grater then a");
    }
     return 0;
  }

Output:
    b is grater then a

else-if Statement:

If the there are sevaral condition then we need to write else-if statement.See the following example.

    #include<stdio.h>
    int main(){
      int a=2, b=2;
      if(a>b){//becomes false
        printf("a is grater then b");
      }
      else if(a==b){//becomes true
        printf("a and b is equal");
      }
      else{
        printf("b is grater then a");
      }
       return 0;
    }

Output:
      a and b is equal

Nasted if-else statement:

Assume you have a condition if the number is grater than 10 and if the number is even then print "EVEN" if it is odd then print "ODD" otherwise print "Number is less than 10". Let's implement it:

        #include<stdio.h>
        int main(){
          int number;
          number = 12;
          if(a>10){//becomes true
              if(number%2==0){//if true
                printf("EVEN");
              }
              else{//if false
                printf("ODD");
              }
          }
         else{//if false
            printf("Number is less than 10");
          }
           return 0;
        }

Output:
        EVEN
Best way of learing

Self learing is the best learing in the world. Discover yourself first then will get what you are And what you want to do .It will push you for self learing.

Why you need to learn coding?

Coding will play a vital role in one's life . It will help to open a new window of thinking . You can think better way than past . It helps to organise all the thing in better way .