Given 2 integer input check whether the 2 input are "Equal" or "Not Equal" and print the corresponding message.
An if
statement allows your program to make decisions based on conditions.
Syntax:
if (condition) { /* code to execute if true */ }
✅ If the condition is true, the code inside the braces runs.
❌ If the condition is false, the code is skipped.
When you want to execute different code based on whether a condition is true or false:
Syntax:
if (condition) { /* true block */ } else { /* false block */ }
Example:
if (a == b) { cout << "Equal"; } else { cout << "Not Equal"; }
Use these operators to compare values in conditions:
==
→ Equal to (checks if two values are the same)!=
→ Not equal to>
→ Greater than<
→ Less than>=
→ Greater than or equal to<=
→ Less than or equal to⚠️ Common mistake: Don't confuse =
(assignment) with ==
(comparison)!
The constraint says input can be up to 10^15, which is too large for a regular int
.
Data type ranges:
int
→ -2×10^9 to 2×10^9long long
→ -9×10^18 to 9×10^18 ✅Since 10^15 exceeds int
range, we use long long
to safely store large numbers.
💡 Tip: Always check the constraints to choose the right data type!
#include <iostream>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
if (a == b) {
cout << "Equal";
} else {
cout << "Not Equal";
}
return 0;
}