easy
0 views

Pass or Fail

Check if a student's mark is passing (>= 40) or failing (< 40) and print the result

Understand the Problem

Problem Statement

The program must accept a mark and print if it is pass or fail. The pass mark is 40.

Constraints

  • Input mark must be a non-negative integer
  • Pass mark is exactly 40
  • Output should be either 'pass' or 'fail' (lowercase)

Examples

Example 1
Input
40
Output
pass
Explanation

Since the mark (40) is equal to the pass mark (40), the student passes.

Example 2
Input
32
Output
fail
Explanation

Since the mark (32) is less than the pass mark (40), the student fails.

Example 3
Input
55
Output
pass
Explanation

Since the mark (55) is greater than the pass mark (40), the student passes.

Solution

#include <stdio.h>

int main() {
    int mark;
    scanf("%d", &mark);
    
    if (mark >= 40) {
        printf("pass\n");
    } else {
        printf("fail\n");
    }
    
    return 0;
}
Time:O(1)
Space:O(1)
Approach:

1. Include stdio.h for input/output functions
2. Declare integer variable 'mark' to store the input
3. Use scanf to read the mark from standard input
4. Use if-else conditional to check if mark >= 40
5. Print 'pass' if condition is true, otherwise print 'fail'
6. Add newline character for proper formatting
7. Return 0 to indicate successful execution

Visual Explanation

Loading diagram...