URI ONLINE JUDGE SOLUTION 1036 - Bhaskara's Formula

Problem

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.


Solution

#include<stdio.h>
#include<math.h>
int main()
{
    double A,B,C,d,r1,r2;
    scanf("%lf%lf%lf",&A,&B,&C);
    d = B*B-4*A*C;
    if(A != 0 && d>=0)
    {
        d = sqrt(d);
        r1 = (d-B)/(2*A);
        r2 = (-d-B)/(2*A);
        printf("R1 = %0.5lf\nR2 = %0.5lf\n",r1,r2);
    }
    else printf("Impossivel calcular\n");
    return 0;

}

Description: Here the problem is about a mathematical equation. We already know a equation ax^2 + bx + c=0 .You have to find the roots of this equation.Solving this equation the first root will be x1=(-b+root(b^2-4*a*c))/(2*a) and the second root will be x1=(-b-root(b^2-4*a*c))/(2*a) .Here if the value of a be zero then the answer will be the undefined.

Comments

Popular posts from this blog

URI ONLINE JUDGE SOLUTION 1021 - Banknotes and Coins

URI ONLINE JUDGE SOLUTION 1040 - Average 3