Algorithm



Problem Name: beecrowd | 1037
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/1037

Interval

Adapted by Neilor Tonin, URI Brazil

Timelimit: 1

You must make a program that read a float-point number and print a message saying in which of following intervals the number belongs: [0,25] (25,50], (50,75], (75,100]. If the read number is less than zero or greather than 100, the program must print the message “Fora de intervalo” that means "Out of Interval".

The symbol '(' represents greather than. For example:
[0,25] indicates numbers between 0 and 25.0000, including both.
(25,50] indicates numbers greather than 25 (25.00001) up to 50.0000000.

Input

The input file contains a floating-point number.

Output

The output must be a message like following example.

Input Sample Output Sample

25.01

Intervalo (25,50]

 

25.00

Intervalo [0,25]

 

100.00

Intervalo (75,100]

 

-25.02

Fora de intervalo

 

Code Examples

#1 Code Example with C Programming

Code - C Programming



#include <stdio.h>

int main()
{
 float n;
 scanf("%f", &n);

 if(n  <  0 || n > 100){
  printf("Fora de intervalo\n");
 }else{
  if(n >= 0 && n <= 25){
   printf("Intervalo [0,25]\n">;
  }else if(n > 25 && n <= 50){
   printf("Intervalo (25,50]\n">;
  }else if(n > 50 && n <= 75){
   printf("Intervalo (50,75]\n");
  }else{
   printf("Intervalo (75,100]\n">;
  }
 }

 return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
25.01

Output

x
+
cmd
Intervalo (25,50]

#2 Code Example with C++ Programming

Code - C++ Programming



#include <iostream>

using namespace std;

int main(){
    
    float f;
    
    cin >> f;
    
    if(f < 0.0000>
         cout << "Fora de intervalo\n";
    else if(f >= 0.0000 && f <= 25.0000>
         cout << "Intervalo [0,25]\n";
    else if(f > 25.0000 && f <=50.0000>
         cout << "Intervalo (25,50]\n";
    else if(f > 50.0000 && f <=75.0000>
         cout << "Intervalo (50,75]\n";
    else if(f > 75.0000 && f <=100.0000>
         cout << "Intervalo (75,100]\n";
    else if(f > 100.0000)
         cout << "Fora de intervalo\n";
         
    return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
25.00

Output

x
+
cmd
Intervalo [0,25]

#3 Code Example with Java Programming

Code - Java Programming



import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        float N;
        Scanner input = new Scanner(System.in);
        N = input.nextFloat();
        
        if (N >= 0) &&  < = 25.0000 {
            System.out.printf("Intervalo [0,25]\n");
        } else if (N >= 25.00001) && <= 50.0000000 {
            System.out.printf("Intervalo [25,50]\n");
        } else if (N >= 50.00001) &&  < = 75.0000000 {
            System.out.printf("Intervalo [0,25]\n");
        } else if (N >= 75.00001) && <= 100.0000000 {
            System.out.print("Intervalo [75,100]\n");
        } else {
            System.out.print("Fora de intervalo\n");
        }
    }
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
100.00

Output

x
+
cmd
Intervalo (75,100]

#4 Code Example with Python Programming

Code - Python Programming



X = float(input())
if X>75 and X<=100:
    print("Intervalo (75,100]")
elif X>50 and X<=75:
    print("Intervalo (50,75]")
elif X>25 and X<=50:
    print("Intervalo (25,50]")
elif X>=0 and X<=25:
    print("Intervalo [0,25]")
else:
    print("Fora de intervalo")
Copy The Code & Try With Live Editor

Input

x
+
cmd
-25.02

Output

x
+
cmd
Fora de intervalo
Advertisements

Demonstration


Previous
#1036 Beecrowd Online Judge Solution 1036 Bhaskara's Formula Solution in C, C++, Java, Python and C#
Next
#1038 Beecrowd Online Judge Solution 1038 Snack Solution in C, C++, Java, Python and C#