Ask Question
20 September, 04:28

Write a program that asks a user for the coefficients?,?, and? and outputs the roots of that equation. Be aware of the following:

a. Be sure that your request for input and your output both have descriptive text.

b. If the roots have an imaginary component, use? when representing the imaginary term in the output. For example, you may output "3 + 7?" as a root.

c. Be sure to handle the cases in which any or all coefficients are equal to zero.

d. If A! = 0, there could be 2 real distinct roots, 2 real identical roots (one root of multiplicity 2), or complex roots.

e. If A = 0, we are left with? + ? = 0, a linear equation with one root.

f. If A = B = 0, we are left with C = 0, so if user entered a non-zero value of C, write a message to the screen indicating this error.

+4
Answers (2)
  1. 20 September, 04:32
    0
    from math import sqrt

    print ("Solving equation ax^2 + bx + c / n")

    a = int (input ('Enter value of a: '))

    b = int (input ('Enter value of b: '))

    c = int (input ('Enter value of c: '))

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

    if (a = = 0 and b = = 0):

    print ("There are no solutions.")

    elif (a = = 0 and b! = 0):

    print ("There is just one root.")

    root = c/b

    print ("Root: ", root)

    elif (determinant < 0):

    print ("There are no real roots")

    x = sqrt (-determinant) / (2*a)

    print ("Root1: %d + %.2fi" % (-b, x))

    print ("Root2: %d + %.2fi" % (-b, - x))

    else:

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

    root2 = (-b - sqrt (determinant)) / (2*a)

    print ("Root1:", root1)

    print ("Root2:", root2)
  2. 20 September, 04:39
    0
    void findRoots (int a, int b, int c)

    { / / If a is 0, then equation is not quadratic, but linear

    if (a = = 0)

    {

    double root = (-1) * c/b;

    printf ("only one root %f", root);

    return;

    }

    int d = b*b - 4*a*c;

    double sqrt_val = sqrt (abs (d));

    if (d > 0)

    {

    printf ("Roots are real and different / n");

    printf ("%f/n%f", (double) (-b + sqrt_val) / (2*a), (double) (-b - sqrt_val) / (2*a));

    }

    else if (d = = 0)

    {

    printf ("Roots are real and same / n");

    printf ("%f", - (double) b / (2*a));

    }

    else / / d < 0

    {

    printf ("Roots are complex / n");

    printf ("%f + i%f/n%f - i%f", - (double) b / (2*a), sqrt_val, - (double) b / (2*a), sqrt_val);

    }

    }

    int main ()

    {

    Int a, b, c;

    printf ("Enter an integer: ");

    scanf ("%d", &a);

    printf ("Enter an integer: ");

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

    printf ("Enter an integer: ");

    scanf ("%d", &c);

    findRoots (a, b, c);

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program that asks a user for the coefficients?,?, and? and outputs the roots of that equation. Be aware of the following: a. Be ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers