URI Online Judge | 1116
Dividing X by Y
Adapted by Neilor Tonin, URI Brazil
Timelimit: 2
Write a program that read two numbers X and Y and print the result of dividing the X by Y. If it's not possible, print the message "divisão impossÃvel".
Input
The input contains an integer number N. This N is the quantity of pairs of integer numbers X and Y read (dividend and divisor).
Output
For each test case print the result of this division with one digit after the decimal point, or “divisão impossÃvel” if it isn't possible to perform the calculation.
Obs.: Be carefull. The division between two integers in some languages generates another integer. Use cast:)
Input Sample | Output Sample |
3 3 -2 -8 0 0 8 | -1.5 divisao impossivel 0.0 |
URI Online Judge Solution 1116 || Dividing X by Y in JAVA
import
java.io.IOException;
import
java.util.Scanner;
public
class
Main {
public
static
void
main(String[] args)
throws
IOException {
int
N;
int
X, Y;
float
result;
Scanner input =
new
Scanner(System.in);
N = input.nextInt();
for
(
int
i =
1
; i <= N; i++) {
X = input.nextInt();
Y = input.nextInt();
if
(Y ==
0
) {
System.out.print(
"divisao impossivel\n"
);
}
else
{
result =(
float
) X / Y;
System.out.printf(
"%.1f\n"
,result);
}
}
}
}
URI Online Judge Solution 1116 || Dividing X by Y in C++
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int n;
float x, y;
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> x >> y;
if(y == 0){
cout << "divisao impossivel" << endl;
}else{
cout << fixed << setprecision(1) << (x/y) << endl;
}
}
return 0;
}
URI Online Judge Solution 1116 || Dividing X by Y in C
#include <stdio.h>
int main()
{
int n, i;
float x, y;
scanf("%d", &n);
for(i = 0; i < n; ++i)
{
scanf("%d%d", &x, &y);
if(y == 0){
printf("divisao impossivel\n");
}else{
printf("%.1f\n", (x/y) );
}
}
return 0;
}
Download dropbox code
URI Question link
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks