Computer Science, asked by nupur1792, 11 months ago

Write a program to calculate roots of quadratic equation

Answers

Answered by preetygirl97
1

Answer:

program to find roots of a quadratic equation

int main() { int a, b, c, d; double root1, root2;

printf("Enter a, b and c where a*x*x + b*x + c = 0\n"); scanf("%d%d%d", &a, &b, &c);

printf("First root = %.2lf\n", root1); printf("Second root = %.2lf\n", root2); }

Answered by Equestriadash
14

I've used Python Programming Language.

The following codes will have to be typed in script mode, saved and then executed.

CODE:

print("The general form of an equation is ax**2 + bx + c.")

a = int(input("Enter a coefficient for 'a':"))

b = int(input("Enter a coefficient for 'b':"))

c = int(input("Enter a coefficient for 'c':"))

print(a, "x**2 +", b, "x +", c, "is your obtained equation.")

d = b**2 - 4*a*c

if d >= 0:

   print("The roots are REAL and UNEQUAL.")

   root1 = (-b + (d)**(1/2)/2*a)

   print(root1, "is one root of the equation.")

   root2 = (-b - (d)**(1/2)/2*a)

   print(root2, "is another root of the equation.")

   print("Therefore,", root1, "and", root2, "are the roots.")

elif d == 0:

   print("The roots are REAL and EQUAL.")

   root1 = (-b + (d)**(1/2)/2*a)

   print(root1, "is one root of the equation.")

   root2 = (-b - (d)**(1/2)/2*a)

   print(root2, "is another root of the equation.")

   print("Therefore,", root1, "and", root2, "are the roots.")

else:

   print("No real roots exist.")

   print("The roots are IMAGINARY.")

   root1 = (-b + (d)**(1/2)/2*a)

   print(root1, "is one root of the equation.")

   root2 = (-b - (d)**(1/2)/2*a)

   print(root2, "is another root of the equation.")

   print("Therefore,", root1, "and", root2, "are the roots.")

Similar questions