Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Write a program that gives us the solution to the quadratic equation i.e. the value of x: ax^2+bx+c=0 ?

Write a program that gives us the solution to the quadratic equation i.e. the value of x: ax^2+bx+c=0 The solution for this equation can be found using the quadratic formula x=(-b±√(b^2-4ac))/2a

user-image
Question added by Saba Mukhtiar
Date Posted: 2017/07/10

Write program to find the value of x using equation x X =2a+3b-10

Bins Thomas
by Bins Thomas , Senior Specialist Solution Architect , Red Hat

 

 

 

 

 

Please fidn the C program which will give you the answers.

 

#include <stdio.h>

#include <math.h>

 

int main()

{

    double a, b, c, deter, root1,root2, rlans, imgans;

 

    printf("Enter the values for a, b and c \\n");

    scanf("%lf %lf %lf",&a, &b, &c);

 

    deter = b*b-4*a*c;

 

    if (deter > 0)

{

        root1 = (-b+sqrt(deter))/(2*a);

        root2 = (-b-sqrt(deter))/(2*a);

 

        printf("root1 = %.2lf and root2 = %.2lf",root1 , root2);

}

 

    else if (deter == 0)

{

        root1 = root2 = -b/(2*a);

 

        printf("root1 = root2 = %.2lf;", root1);

}

 

    else

{

        rlans = -b/(2*a);

        imgans = sqrt(-deter)/(2*a);

        printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", rlans, imgans, rlans, imgans);

}

 

    return 0;

}

More Questions Like This