URI Online Judge | 1036
Fórmula de Bhaskara
Adaptado por Neilor Tonin, URI
Brasil
Timelimit: 1
Leia 3 valores de ponto flutuante e efetue o cálculo das raízes da equação de Bhaskara. Se não for possível calcular as raízes, mostre a mensagem correspondente “Impossivel calcular”, caso haja uma divisão por 0 ou raiz de numero negativo.
Entrada
Leia três valores de ponto flutuante (double) A, B e C.
Saída
Se não houver possibilidade de calcular as raízes, apresente a mensagem "Impossivel calcular". Caso contrário, imprima o resultado das raízes com 5 dígitos após o ponto, com uma mensagem correspondente conforme exemplo abaixo. Imprima sempre o final de linha após cada mensagem.
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.
v = input().split()
a, b, c = v
a = float(a)
b = float(b)
c = float(c)
if a == 0.0 or (b ** 2 - 4 * a * c) < 0:
print('Impossivel calcular')
else:
x1 = (- b + (b ** 2 - 4 * a * c) ** (1/2) )/(2 * a)
x2 = (- b - (b ** 2 - 4 * a * c) ** (1/2) )/(2 * a)
print('R1 = {:.5f}'.format(x1))
print('R2 = {:.5f}'.format(x2))
Nenhum comentário:
Postar um comentário