Welcome

>>>Welcome to my "CODE BAZAR"
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others
Code marshal
URI online judge
Others

Update ✔✔✔ Upcoming programming book (.pdf) "Programming Contest (data structures and algorithms) by Md. Mahbub Hasan & "Graph Algorithms" by Safayat Asraf "****** Date: 20 March, 2019****Hazrat Ali****

Saturday, 12 November 2016

URI-1036

URI Online Judge | 1036

Bhaskara's Formula

Adapted by Neilor Tonin, URI  Brazil
Timelimit: 1
Problem link click here
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


Solution...

#include<stdio.h>
#include<math.h>
int main(){
        float a,b,c,R1,R2,z;
        scanf("%f%f%f",&a,&b,&c);
        z=b*b-4*a*c;
        R1=(-b+sqrt(z))/(2*a);
        R2=(-b-sqrt(z))/(2*a);


       if(a==0 || z<0){
                printf("Impossivel calcular\n");
       }

       else{
              printf("R1 = %.5f\nR2 = %.5f\n",R1,R2);
       }
       return 0;
}


No comments:

Post a Comment