Saturday 22 December 2018

if-else statement


if-else statement :
                                This statement contains a single condition with two different blocks of statements. The flowchart and the syntax of “ if-else “ statement is shown below :
                

Syntax:      if(condition)
                                     {
                                                true statement-1;
                                     }
                                     else
                                     {
                                                false statement-2;
                                     }
                                     Statement-3;
                In this if-else statement, first the condition will be checked. If the condition is true then the true statement-1 will be executed and after that statement-3 will be executed. But if the condition is false then the false statement-2 will be executed and then the statement-3 will be executed.
Ex:          #include<stdio.h>
                #include<conio.h>
                void main()
                {
                      int a,b,max;
                      clrscr();
                      printf(“Enter the values of a and b:”);
                      scanf(“%d%d”,&a,&b);
                      if(a>b)
                      {
                                max=a;
                      }
                      else
                       {
                                max=b;
                       }
                       printf(“\n Maximum value is :%d”,max);
                       getch();
                }

No comments:

Post a Comment