Wednesday, March 30, 2016

URI 1037 problem solution in C, C++ and java language || Interval

Main link : URI Web page - Problem No : 1037 Link

URI Online Judge | 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 SampleOutput Sample
25.01Intervalo (25,50]
25.00Intervalo [0,25]
100.00Intervalo (75,100]
-25.02Fora de intervalo


URI SOLUTION 1037 IN C Language

#include<stdio.h>
int main()
{
 float n;
 scanf("%f", &n);  //take value from the user
 if(n < 0 || n > 100){     //implementing the above logic
  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;
}

URI 1037 Solution in java language :

 import java.io.IOException;

import java.util.Scanner;
public class Main {
  
    public static void main(String[] args) throws IOException {
  
        float N;
        Scanner input =new Scanner(System.in);
        N = input.nextFloat();
        //Set the range
        if (N >=0 && N <= 25.0000) {
            System.out.printf("Intervalo [0,25]\n");
        }else if (N >= 25.00001 && N <= 50.0000000) {
            System.out.printf("Intervalo (25,50]\n");
        }else if (N >= 50.00001 && N <= 75.0000000) {
            System.out.printf("Intervalo (50,75]\n");
        }else if (N >= 75.00001 && N<=100.0000000) {
            System.out.printf("Intervalo (75,100]\n");
        }else {
            System.out.print("Fora de intervalo\n");
        }
  
    }
  
}

URI SOLUTION 1037 IN C++ Language

    #include <iostream>
    using namespace std;
    int main()
    {
     float n;
     cin >> n;  //take value from the user
     if(n < 0 || n > 100){     //implementing the above logic
      cout << "Fora de intervalo" << endl;
     }else{
      if(n >= 0 && n <= 25){
       cout << "Intervalo [0,25]" << endl;
      }else if(n > 25 && n <= 50){
       cout << "Intervalo (25,50]" << endl;
      }else if(n > 50 && n <= 75){
       cout << "Intervalo (50,75]" << endl;
      }else{
       cout << "Intervalo (75,100]" << endl;
      }
     }
     return 0;
    }

Download Java accepted source code

Download C accepted source code

Download C++ accepted source code

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.