How do you find the roots of a quadratic equation using switch case in c?

How do you find the roots of a quadratic equation using switch case in c?

Switch the value of switch(discriminant > 0) . The expression (discriminant > 0) can have two possible cases i.e. case 0 and case 1 . For case 1 means discriminant is positive. Apply formula root1 = (-b + sqrt(discriminant)) / (2*a); to compute root1 and root2 = (-b – sqrt(discriminant)) / (2*a); to compute root2 .

How do you write ac program to find the roots of a quadratic equation?

Design (Algorithm)

  1. Start.
  2. Read a, b, c values.
  3. Compute d = b2 4ac.
  4. if d > 0 then. r1 = b+ sqrt (d)/(2*a) r2 = b sqrt(d)/(2*a)
  5. Otherwise if d = 0 then. compute r1 = -b/2a, r2=-b/2a. print r1,r2 values.
  6. Otherwise if d < 0 then print roots are imaginary.
  7. Stop.

How do you write a quadratic equation in c?

Program 2: find a b and c in a quadratic equation

  1. #include
  2. #include
  3. int main(){
  4. float a,b,c;
  5. float d,root1,root2;
  6. printf(“Enter quadratic equation in the format ax^2+bx+c: “);
  7. scanf(“%fx^2%fx%f”,&a,&b,&c);
  8. d = b * b – 4 * a * c;

How do you find the roots of a quadratic equation in C++?

For a quadratic equation ax2+bx+c = 0 (where a, b and c are coefficients), it’s roots is given by following the formula. The term b2-4ac is known as the discriminant of a quadratic equation. The discriminant tells the nature of the roots. If discriminant is greater than 0, the roots are real and different.

How do I find the roots of a quadratic equation?

For a quadratic equation ax2 + bx + c = 0,

  1. The roots are calculated using the formula, x = (-b ± √ (b² – 4ac) )/2a.
  2. Discriminant is, D = b2 – 4ac. If D > 0, then the equation has two real and distinct roots. If D < 0, the equation has two complex roots.
  3. Sum of the roots = -b/a.
  4. Product of the roots = c/a.

Where are the roots in a quadratic equation?

The roots of a function are the x-intercepts. By definition, the y-coordinate of points lying on the x-axis is zero. Therefore, to find the roots of a quadratic function, we set f (x) = 0, and solve the equation, ax2 + bx + c = 0.

How do you write ac program?

h . int main() The main() function is the entry point of every program in c language. printf() The printf() function is used to print data on the console….To write the first c program, open the C console and write the following code:

  1. #include
  2. int main(){
  3. printf(“Hello C Language”);
  4. return 0;
  5. }

How do you find the roots of a quadratic equation?

How do I get roots in C++?

The sqrt() function in C++ returns the square root of a number. This function is defined in the cmath header file. Mathematically, sqrt(x) = √x .

How do you find roots?

To calculate n√a:

  1. Estimate a number b.
  2. Divide a by bn-1. If the number c returned is precise to the desired decimal place, stop.
  3. Average: [b × (n-1) + c] / n.
  4. Repeat step two.

How many roots does the quadratic equation have?

two
A quadratic equation with real or complex coefficients has two solutions, called roots.

What is root in quadratic equation?

Roots are also called x-intercepts or zeros. The roots of a function are the x-intercepts. By definition, the y-coordinate of points lying on the x-axis is zero. Therefore, to find the roots of a quadratic function, we set f (x) = 0, and solve the equation, ax2 + bx + c = 0.

How to find roots of quadratic equation using switch case?

Step by step descriptive logic to find roots of quadratic equation using switch case. Input coefficients of quadratic equation. Store it in some variable say a, b and c. Find discriminant of given equation using formula i.e. discriminant = (b * b) – (4 * a * c).

How to find the roots of a quadratic equation with discriminant?

Where discriminant of the quadratic equation is given by Depending upon the nature of the discriminant, formula for finding roots can be given as: Case 1: If discriminant is positive. Then there are two real distinct roots given by. Case 2: If discriminant is zero.

How many roots can a quadratic equation have in C?

A Quadratic Equation in C can have two roots, and they depend entirely upon the discriminant. The mathematical representation of a Quadratic Equation is ax²+bx+c = 0.

What is the standard form of a quadratic equation?

The standard form of a quadratic equation is: The term b 2 -4ac is known as the discriminant of a quadratic equation. It tells the nature of the roots. If the discriminant is greater than 0, the roots are real and different. If the discriminant is equal to 0, the roots are real and equal.