Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Relational Operators Org

Uploaded by

megaslayer999
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Relational Operators Org

Uploaded by

megaslayer999
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Relational

Operators
Programming
Fundamentals

Hamza
Sani
Presentation
Includes
 Introduction
 Example
 Syntax
 Flow Chart
 Program

2/1/20XX PRESENTATION TITLE 2


Introduction
Relational operators in C++ are used to compare
two values (variables, constants, or expressions).

They return a Boolean value (true or false)


based on the comparison result. These operators are
commonly used in If-else and Loops.

There are 6 types of Relational Operators.

3
Types
of Relational
Operators
and their functions
Operator Symbol Description Example Returns

true if a is equal to b,
Equal to == Checks if two operands are equal a == b
else false

true if a is not equal to


Not equal to != Checks if two operands are not equal a != b
b, else false

Checks if left operand is greater than right true if a is greater than


Greater than > a>b
operand b, else false

true if a is less than b,


Less than < Checks if left operand is less than right operand a<b
else false

true if a is greater than


Greater than Checks if left operand is greater than or equal to
>= a >= b or equal to b, else
or equal to right operand
false

Less true if a is less


Less than or Checks if left operand is less than or equal to
<= a<=b than or equal to b,
equal to right operand
else false 5
Purpose of using Relational Operators

 Condition Checking: To check conditions in control statements.

 Loops: To control how long loops run (e.g., run while a condition is
true).

 Comparison: To compare values for equality or order (greater,


smaller).
Syntax
In programming, relational operators are placed between
two operands (values or variables) to compare them.
 Syntax
operand1 operator operand2

 Example

int a = 9, b = 10 ;

cout << a < b ; // 1

7
Using in Code
Expected
Output

In this output:
 1 means the condition is true
 0 means the condition is false
Program Example

10
Output
First possible
output

Second possible
output

Third possible
output
Flow
Chart
Of above program
Another
Example
What the above program do?

 Takes Input: It asks the user to enter a percentage score (for example, 85). This score
is stored in a variable named numbers

 Checks the Score Range: The program then compares the  Displays the Grade: Based on the score,
input score against different ranges to determine the the program prints out the grade (A, B,
grade: C, D, E, or F) to the screen.
• If the score is 90 or above, it assigns an A grade.
• If the score is between 80 and 89, it assigns a B grade.
• If the score is between 70 and 79, it assigns a C grade.
• If the score is between 60 and 69, it assigns a D grade.
• If the score is between 50 and 59, it assigns an E grade.
• If the score is below 50, it assigns an F grade and also
displays "Fail."
THANK
YOU
Hamza Sani

19 NOVEMBER 2024 RELATIONAL OPERATORS 15

You might also like