Determine whether
the number x is outside the interval [a; b]. The number x
is outside the interval [a; b] if either x <
a or x > b.
Input. Three integers x, a, b,
each not exceeding 109 in
absolute value.
Output. Print “OUT” if the
number x does not belong to the interval [a;
b]. Otherwise, print “IN”.
Sample input 1 |
Sample output 1 |
7 2 7 |
IN |
|
|
Sample input 2 |
Sample output 2 |
-5 1 1 |
OUT |
conditional
statement
Let’s combine the conditions x < a and x > b using the or (||) operator.
Algorithm
implementation
Read the input data.
scanf("%d %d %d", &x,
&a, &b);
Print
the answer depending on whether the number x is outside or inside the
interval [a; b].
if (x < a || x > b)
printf("OUT\n");
else
printf("IN\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("OUT");
else
System.out.println("IN");
con.close();
}
}
Python implementation
Read the
input data.
x, a, b = map(int,input().split())
Print the answer depending on whether the
number x is outside or inside the interval [a; b].
if x < a or x > b:
print("OUT")
else:
print("IN")