Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dejibimbolaAyo/b036df8af979e19c325faa74487e9e46 to your computer and use it in GitHub Desktop.
Save dejibimbolaAyo/b036df8af979e19c325faa74487e9e46 to your computer and use it in GitHub Desktop.
algorithm for quadratic equation
//prompt user to enter coefficients of the quadratic equation
Enter value for a
Enter value for b
Enter value for c
square_b= b*b
neg_b= b* (-1)
two_a= 2*a
neg_four_a_c= 4*a*c*(-1)
square_b_minus_4ac= square_b - neg_four_a_c
if (square_b_minus_4ac < 0) //if b2-4ac (the discriminant) is less than 0, then the quadratic eqn has no solution
output: quadratic equation has no solution
else
root_of_square_b_4ac= Root of square_b_minus_4ac
upper_calc_one= neg_b + root_of_square_b_4ac
upper_calc_two= neg_b - root_of_square_b_4ac
x_one= upper_calc_one / two_a
x_two= upper_calc_two / two_a
output:
x_one, x_two
@dejibimbolaAyo
Copy link
Author

//prompt user to enter coefficients of the quadratic equation

Enter value for a
Enter value for b
Enter value for c

square_b= b_b
neg_b= b_ (-1)
two_a= 2_a
four_a_c= 4_a*c
square_b_minus_4ac= square_b - four_a_c

if (square_b_minus_4ac < 0) //if b2-4ac (the discriminant) is less than 0, then the quadratic eqn has no solution
output: quadratic equation has no solution
else
root_of_square_b_4ac= Root of square_b_minus_4ac

upper_calc_one= neg_b + root_of_square_b_4ac
upper_calc_two= neg_b - root_of_square_b_4ac

x_one= upper_calc_one / two_a
x_two= upper_calc_two / two_a

output:
x_one, x_two

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment