Given a student's mark as input, print output as Pass/Fail based on the input
mark < 35 print Fail
mark>=35 print Pass
The <
operator checks if the left value is strictly less than the right value.
Syntax: value1 < value2
Returns: true
if value1 is less than value2, otherwise false
Examples:
34 < 35
→ TRUE (34 is less than 35)35 < 35
→ FALSE (35 is NOT less than 35, they're equal)36 < 35
→ FALSE (36 is greater than 35)0 < 35
→ TRUE (0 is less than 35)✅ Key point: The value must be strictly smaller, not equal!
C++ provides six comparison operators:
==
→ Equal to (checks if two values are the same)!=
→ Not equal to<
→ Less than>
→ Greater than<=
→ Less than or equal to>=
→ Greater than or equal toFor our problem:
We could also write it as: if (marks >= 35) cout << "PASS"; else cout << "FAIL";
Both approaches are correct! The choice depends on which logic feels more natural.
The rule:
Breaking it down:
if (marks < 35)
→ Check if marks are below passing threshold
Boundary case:
Marks = 35 is PASS (exactly at the threshold)
Marks = 34 is FAIL (just below the threshold)
Example 1: marks = 34
marks = 34
if (34 < 35)
34 < 35
is TRUEcout << "FAIL";
Example 2: marks = 35
marks = 35
if (35 < 35)
35 < 35
is FALSE (equal, not less than)cout << "PASS";
Example 3: marks = 90
marks = 90
if (90 < 35)
90 < 35
is FALSEcout << "PASS";
In this problem, we use int
instead of long long
. Why?
Constraint analysis:
0 <= INPUT <= 10^9
Data type ranges:
int
→ -2×10^9 to 2×10^9 (approximately)long long
→ -9×10^18 to 9×10^18✅ Since 10^9 fits comfortably within int
range, we use int
for efficiency.
🔄 If the constraint was 10^15, we'd need long long
.
💡 Pro tip: Always choose the smallest data type that can handle your constraints to save memory!
💡 Tip: When comparing values, make sure you understand the boundary conditions (like exactly 35 in this case)!
#include <iostream>
using namespace std;
int main() {
int marks;
cin >> marks;
if (marks < 35)
cout << "FAIL";
else
cout << "PASS";
return 0;
}