Conditional Statement


Conditional Statement

Sometimes, we need to perform different actions based on different conditions. It can be perform with the help of Relational operator or conditional statement.

Conditional Operator

>greater than
Example:- a=4 and b= 2; a>b
a is greater than b
<less than
Example:- a=2 and b=4; a
a is less than b.
>=greater than or equal to
<=less than or equal to
==equals to
Example: a=2 and b=2;a==b
a is equals to b
!=is not equals to
Example: a=2 and b=4; a!=b
a is not equals to b

Relational Operator

&&ANDif both condition true than statement will be execute.
||ORany one condition true than statement will be execute
!NOTNOT.

Conditional Or Branch Statements

The if Statement(One way selection/decision)

An if statement is a single selection or decision statement.it used when we have only one alternative .

Syntax:-
If(expression)
     {
        statement 1
        statement 2
         .
         .
         statement n
      }
the statements are executed if the condition is true.

W.A.P to print the largest no:-

#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,big;
   printf("Enter two numbers\n");
   scanf("%d%d",&a,&b);  
   big=a;
  if(b>big)
      {              
        big=b;        
       }  
   printf("largest number=%d",big);
   getch();
  }

Output

 
Enter two numbers
3  4
largest number=4