URI Online Judge Solution 1036 | Bhaskaras Formula - URI 1036 Solution in C,C++,Python

URI Online Judge Solution  1036 | Bhaskara's Formula - URI 1036 Solution in C,C++,Python

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 (double) 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.1

R1 = -0.29788
R2 = -1.71212

0.0 20.0 5.0

Impossivel calcular

10.3 203.0 5.0

R1 = -0.02466
R2 = -19.68408

URI Online Judge Solution  1036 | Bhaskaras Formula - URI 1036 Solution in C,C++,Python:


  URI Problem 1036 Solution in C :   

  URI Online Judge 1036 Solve  in C :                                                                             
#include<bits/stdc++.h>
#include<math.h>
using namespace std;

int main(){
    double a,b,c,t,R1,R2;
    cin>>a>>b>>c;

    if(((b*b)-4*a*c)<0 ||a==0){
        cout<<"Impossivel calcular"<<endl;
    }else{
         t=sqrt((b*b)-4*a*c);
         R1=((-b + t) / (2 * a));
         R2=((-b - t) / (2 * a));
         cout<<fixed;
         cout<<setprecision(5)<<"R1 = "<<R1<<endl;
         cout<<setprecision(5)<<"R2 = "<<R2<<endl;
    }
    return 0;
}

0 Response to URI Online Judge Solution 1036 | Bhaskaras Formula - URI 1036 Solution in C,C++,Python

Post a Comment