Friday, December 14, 2012 #

what is Relational operator in C?

Relational operator
    Relational oprerator are used   to compare two values depending on their   relation .two operands.

 An expression that then contain the relational operator is called relational expression . if the relation is true then it return s the values1, if the relation   is false then it return the value 0. These operators are-

Operator                                  Meaning
<                                               less than

<=                                             less than or equal to

==                                              equal

!=                                                not equal

>                                                 greater then

>=                                               Greater than or equal

Let a=9 and b=5, then the operation with relational operator are-
Expression                                result

a<b                                             false(0)

a<=b                                           false (0)

a==b                                           false(0)

a!=b                                             true(1)
a>b                                              true(1)

a>=b                                            true(1)

/* program to understand the use of relational operator*/
 Void main()
Int a,b;

Printf(“ enter first number for a :”);

Scanf(“%d”,&a) ;
Printf(“enter the second number for b”);
Scanf( “%d”,&b);
If(a<b)/* relational operator with if (in control statement)*
Printf(“%d is less than %d\n”,a,b);
If(a<= b)
Printf(“%d is less or equal to %d\n”,a,b);
Printf(“%d is equal to %d\n”,a,b);
If(a !=b)
Primntf(“%d is not equal to %d\n”,a,b);
If (a>b)
Printf(“%d is greater than %d\n”,a,b);
If (a>=b)
Printf(“%d is greater or equal to %d \n”,a,b);
After run :
First number for a:12
Second number for b:7
12 is not equal to 7
12 is greater than 7
12 is greater or equal to 7    

posted @ Friday, December 14, 2012 4:06 PM | Feedback (0)

Copyright © Afsana Bano

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski

Advertisements at