The roots of the quadratic equation ax2 + bx + c = 0, a ≠0 are given by the following formula:

In this formula, the term b2–4ac is called the discriminant. If b2–4ac = 0, then the equation has a single (repeated) root. If b2–4ac > 0, the equation has two real roots. If b2–4ac<0, the equation has two complex roots.

Write a program that prompts the user to input the value of a (the coefficient of x2), b (the coefficient of x), and c (the constant term) and outputs the type of roots of the equation. Furthermore, if b2–4ac≥0, the program should output the roots of the quadratic equation.

Respuesta :

Answer:

// here is program in C.

// include header

#include <stdio.h>

#include<math.h>

// main function

int main()

{

 // variables

 int a,b,c;

 float d;

 printf("enter the value of a,b,c :");

 // read the value of a,b,c

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

 // find the discriminant

 d=b*b-(4*a*c);

 // if d=0 then no real root

 if(d<0)

printf("The equation has no real roots \n");

//// d=0 then equation has one root

 else if(d==0)

 {

   // find the root

 float root=-b/(2*a);

 printf("only root of the equation is:%f \n",root);

 }

 // d>=0 then equation has two real roots

 else if(d>0)

 {

     // calculate both roots

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

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

     // print both the roots

     printf("first root of the equation is:%f \n",root1);

     printf("second root of the equation is:%f \n",root2);

 }

   return 0;

}

Explanation:

Read the value of a,b,c from user.Calculate discriminant "d" as b^2 - 4ac . If the value of discriminant(d) is less than 0 then there will be no real root. If discriminant(d) is equal to 0 then quadratic equation has only one root which is -b/2a. Calculate the only root and print it.If discriminant(d) is greater than 0 then quadratic equation has two root as root1= (-b + sqrt(b^2 - 4ac)) / (2a) and root2 = (-b - sqrt(b^2 - 4ac)) / (2a). calculate both the roots and print them.

Output:

enter the value of a,b,c :1 6 4

first root of the equation is:-0.763932

second root of the equation is:-5.236068

Answer:

should be C

Explanation:

EDG2021 comment for my mixtape

ACCESS MORE