8614. Inside the interval

 

Determine whether the number x belongs to the interval [a; b]. The number x belongs to the interval [ab] if a ≤ x ≤ b.

 

Input. Three integers xab, each not exceeding 109 in absolute value.

 

Output. Print “YES” if the number x belongs to the interval [ab]. Otherwise, print “NO”.

 

Sample input 1

Sample output 1

4 2 6

YES

 

 

Sample input 2

Sample output 2

5 10 15

NO

 

 

SOLUTION

conditional statement

 

Algorithm analysis

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

 

Algorithm implementation

Read the input data.

 

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

 

Print the answer depending on whether x belongs to the interval [a; b].

 

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 x belongs to the interval [a; b].

 

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 x belongs to the interval [a; b].

 

if a <= x <= b:

  print("YES")

else:

  print("NO")