[URI Online Judge] – 1037 – Interval

The input file contain a float-point number. Your task is to print a message saying in which of following intervals the number belongs: [0,25] (25,50], (50,75], (75,100]. If the input is less than zero or greather than 100, the program must print the message “Fora de intervalo” that means “Out of Interval”.

Examples:
[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.

Sample Input Sample Output
25.01 Intervalo (25,50]
25.00 Intervalo [0,25]
100.00 Intervalo (75,100]
-25.02 Fora de intervalo

Solution:

#include <cstdio>
int main(){
double n;

scanf(“%lf”, &n);
if (n >= 0.0 && n <= 25.0)
printf(“Intervalo [0,25]\n”);
else if (n > 25.0 && n <= 50.0)
printf(“Intervalo (25,50]\n”);
else if (n > 50.0 && n <= 75.0)
printf(“Intervalo (50,75]\n”);
else if (n > 75.0 && n <= 100.0)
printf(“Intervalo (75,100]\n”);
else
printf(“Fora de intervalo\n”);
return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s