Table of Contents

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

Solve Code

#include <stdio.h>
#include <math.h>


int main()
{
    float a,b,c,m,n,p;
    scanf("%f%f%f",&a,&b,&c);
    m=(b*b)-(4*a*c);
    if(m<0)
    {
        printf("Impossivel calcular\n");
    }
    else if (a == 0)
    {
        printf("Impossivel calcular\n");
    }
    else
    {
        n=((-b) + sqrt(m))/(a+a);
        p=((-b) - sqrt(m))/(a+a);
        printf("R1 = %.5f\n",n);
        printf("R2 = %.5f\n",p);


    }
    return 0;
}
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Share on pinterest
Pinterest
Share on whatsapp
WhatsApp
Share on email
Email
Md. Nurnobi Hosen
Md. Nurnobi Hosen

Student of Computer Science and Engineering at Daffodil International University,Main Campus ,Dhanmondi.
Web and App Developer also expart of wordpress customization

All Blog Posts »
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x