quadratic equation – Programmerbay https://programmerbay.com A Tech Bay for Tech Savvy Fri, 26 Aug 2022 12:27:40 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 https://programmerbay.com/wp-content/uploads/2019/09/cropped-without-transparent-32x32.jpg quadratic equation – Programmerbay https://programmerbay.com 32 32 Design the test cases and test the program of Quadratic Equation by using Data Flow testing https://programmerbay.com/design-the-test-cases-and-test-the-program-of-quadratic-equation-by-using-data-flow-testing/ https://programmerbay.com/design-the-test-cases-and-test-the-program-of-quadratic-equation-by-using-data-flow-testing/#respond Sat, 23 Nov 2019 08:05:42 +0000 https://programmerbay.com/?p=5492 Data flow testing doesn’t deal with the flow of the program, instead, it tracks which variable is used when. It means that it simply checks the initialization and usability of variables.

In this, we will drive test cases using Data flow testing approach by considering the Quadratic equation example. The first step is to create a flow graph from the code of the Quadratic Equation.

path testing data flow graph

Using the flow graph, create a Decision to Decision Graph ( DD Graph) by converting each set of consecutive nodes into a single node.

Path testing

Replace these numbers with correspondent DD nodes.

path testing DD graph

Create a Defined and Used node table to get a clear view of variable usage.

DU or DC for Quadratic equation

On the basis of the above table, we will generate du and dc path respectively.

DU or DC for Quadratic equation 2

All the ‘Y’ in the above table are DC path and ‘Path nodes’ are DU paths.

Now, create the test cases from input provided by the user in such a way that all the paths get covered.

Test IDabcExpected OutputProgram OutputTested Outcome
1055Not QuadraticNot QuadraticPass
2155RealRealPass
3955ImaginaryImaginaryPass
45105EqualEqualPass
5-155Invalid InputInvalid InputPass

]]>
https://programmerbay.com/design-the-test-cases-and-test-the-program-of-quadratic-equation-by-using-data-flow-testing/feed/ 0
C Program for Quadratic Equation https://programmerbay.com/c-program-to-determine-roots-of-a-quadratic-equation/ https://programmerbay.com/c-program-to-determine-roots-of-a-quadratic-equation/#respond Sat, 21 Sep 2019 16:45:19 +0000 https://programmerbay.com/?p=5310 The program calculates whether a quadratic equation has real roots or imaginary roots.

A quadratic equation is a polynomial equation, having highest degree of two. The equation is represented in the form of ax2+bx+c where a can’t be 0, c is constant, a and b are coefficients. There can be two answers of x which is termed as roots.

3

This Quadratic formula is applied only when b2– 4ac >= 0.
such that,
If b2– 4ac > 0 , means the eqn. has more than one real roots
if b2– 4ac = 0 , represent equal or single root
if b2– 4ac <0, represents imaginary root
Lastly, if a is 0, then the equation would not be considered as a quadratic equation.

quadratic equation in c

A quadratic equation is an equation having a degree of 2.  There are 4 possibilities, these are real roots, equal roots, imaginary roots and not a quadratic equation.

Steps to calculate quadratic equation

  • Read a, b, c values
  • if a == 0, then it’s not a quadratic equation
  • else,
    calculate result = b2 – 4ac
    • if result > 0 then
      compute the real roots using the formula
      print root1,root2 values
    • Else if result = 0 then
      compute the equal roots using the formula
      print root1,root2 values
    • Else if result < 0 then
      roots are imaginary
      print no solution

C Program for Quadratic Equation

Program:

#include<conio.h>
#include<stdio.h>
#include<math.h>
void main (){
  float a, b, c, result;
  printf (" ax^2 + bx + c, \n enter the values of a, b and c : = ");
  scanf ("%f %f %f", &a, &b, &c);

  result = (b * b) - (4 * a * c);
  if (a == 0)
    printf ("The equation is not a quadratic equation");
  else if (result > 0)
    {
      result = sqrt (result);
      printf ("Real roots are, %f,%f \n", (-b - result) / (2 * a),
        (-b + result) / (2 * a));
    }
  else if (result == 0)
    {
      result = sqrt (result);
      printf ("equal root, %f,%f \n", (-b) / (2 * a), (-b) / (2 * a));
    }
  else
    {
      printf ("Root are imaginary ;\n No Solution");
    }

  getch ();
}

 

Output:

Imaginary Roots or No solution

ax^2 + bx + c, 
 enter the values of a, b and c : = 11 5 5
Root are imaginary ;
 No Solution

Real roots:

 ax^2 + bx + c, 
 enter the values of a, b and c : = 5 5 1
Real roots are, -0.723607,-0.276393 

 

Equal roots:

 ax^2 + bx + c, 
 enter the values of a, b and c : = 5 10 5
equal root, -1.000000,-1.000000 

Not Quadratic

 ax^2 + bx + c, 
 enter the values of a, b and c : = 0 5 5 
The equation is not a quadratic equation

]]>
https://programmerbay.com/c-program-to-determine-roots-of-a-quadratic-equation/feed/ 0