Inside the interval#8614

Inside the interval (Editorial)

In the C language, it is not possible to express the condition a \leq x \leq b directly. Let's combine the conditions a \leq x and x \leq b using the “and” operator ().

Algorithm implementation

Read the input data.

scanf("%d %d %d", &x, &a, &b);

Print the answer depending on whether belongs to the interval .

if (x >= a && x <= b)
    printf("YES\n");
else
    printf("NO\n");

Java implementation

import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner con = new Scanner(System.in);
        int x = con.nextInt();
        int a = con.nextInt();
        int b = con.nextInt();
        if (x >= a && x <= b)
            System.out.println("YES");
        else
            System.out.println("NO");
        con.close();
    }
}

Python implementation

Read the input data.

x, a, b = map(int,input().split())

Print the answer depending on whether belongs to the interval .

if x >= a and x <= b:
  print("YES")
else:
  print("NO")

Python implementation — the concise condition

Read the input data.

x, a, b = map(int,input().split())

Print the answer depending on whether belongs to the interval .

if a <= x <= b:
  print("YES")
else:
  print("NO")