Comparison Operators

Comparison Operators

Easy C++ Operators 41 views
Explanation Complexity

Problem Statement

Compare two numbers using all comparison operators.
Real Life: Like comparing prices, ages, scores etc.

Input Format

Two integers a and b.

Output Format

Result of all comparison operations between a and b.

Example

a = 10
b = 20
a == b : false
a != b : true
a > b  : false
a < b  : true
a >= b : false
a <= b : true

Constraints

• Integer values

• Standard comparison operators only

Concept Explanation

Comparison operators are used to compare two values.
They return either true or false.
This is used in real life for comparing prices, ages, scores, etc.

Step-by-Step Explanation

1.Take two numbers a and b.

2.Compare them using == (equal to).

3.Compare them using != (not equal to).

4.Compare them using > (greater than).

5.Compare them using < (less than).

6.Compare them using >= (greater than or equal to).

7.Compare them using

Concept Explanation

Comparison operators are used to compare two values.
They return either true or false.
This is used in real life for comparing prices, ages, scores, etc.

Step-by-Step Explanation

1.Take two numbers a and b.

2.Compare them using == (equal to).

3.Compare them using != (not equal to).

4.Compare them using > (greater than).

5.Compare them using < (less than).

6.Compare them using >= (greater than or equal to).

7.Compare them using

Input / Output Format

Input Format
Two integers a and b.
Output Format
Result of all comparison operations between a and b.
Constraints
• Integer values

• Standard comparison operators only

Examples

Input:
a = 10 b = 20
Output:
a == b : false a != b : true a > b : false a < b : true a >= b : false a <= b : true

Example Solution (Public)

C++
void operator_q3_comparison() {
    int a = 15;
    int b = 20;
    
    cout << "a = " << a << ", b = " << b << endl;
    cout << "a == b: " << (a == b) << endl;
    cout << "a != b: " << (a != b) << endl;
    cout << "a > b: " << (a > b) << endl;
    cout << "a < b: " << (a < b) << endl;
    cout << "a >= b: " << (a >= b) << endl;
    cout << "a <= b: " << (a <= b) << endl;
}

Official Solution Code

void operator_q3_comparison() {
    int a = 15;
    int b = 20;
    
    cout << "a = " << a << ", b = " << b << endl;
    cout << "a == b: " << (a == b) << endl;
    cout << "a != b: " << (a != b) << endl;
    cout << "a > b: " << (a > b) << endl;
    cout << "a < b: " << (a < b) << endl;
    cout << "a >= b: " << (a >= b) << endl;
    cout << "a <= b: " << (a <= b) << endl;
}
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.