Wednesday, March 30, 2016

URI 1036 Solution in Java language || Bhaskar's Formula

Go to main link in URI online judge to solve this problem :

GO URI ONLINE JUDGE ---> Problem No : 1036


URI Online Judge | 1036

Bhaskara's Formula

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Read 3 floating-point numbers. After, print the roots of bhaskara’s formula. If it's impossible to calculate the roots because a division by zero or a square root of a negative number, presents the message “Impossivel calcular”.

Input

Read 3 floating-point numbers A, B and C.

Output

Print the result with 5 digits after the decimal point or the message if it is impossible to calculate.
Input SamplesOutput Samples
10.0 20.1 5.1R1 = -0.29788
R2 = -1.71212
0.0 20.0 5.0Impossivel calcular
10.3 203.0 5.0R1 = -0.02466
R2 = -19.68408
10.0 3.0 5.0Impossivel calcular

URI 1036 Solution in java language:


import java.util.Scanner; //Problem public class URI_1036 { public static void main(String[] args) { float A, B, C, R1, R2; Scanner input =new Scanner(System.in); A = input.nextFloat(); B = input.nextFloat(); C = input.nextFloat(); if ((A == 0) || (((B*B) -(4*A*C)) < 0)) { System.out.print("Impossivel calcular\n"); }else { R1 =(float) ((-B + Math.sqrt(((B*B) -(4*A*C)))) / (2*A)); R2 =(float) ((-B - Math.sqrt(((B*B) -(4*A*C)))) / (2*A)); System.out.printf("R1 = %.5f\n", R1); System.out.printf("R2 = %.5f\n", R2); } } }

For any problem in this problem , comment please. I'll help as I can.

See other solution in java , C, C++ language :

Go to Home








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.