Skip to content

Instantly share code, notes, and snippets.

@bllaude
Created July 31, 2022 06:26
Show Gist options
  • Select an option

  • Save bllaude/004933327999e36b92b3443d8ff98fe3 to your computer and use it in GitHub Desktop.

Select an option

Save bllaude/004933327999e36b92b3443d8ff98fe3 to your computer and use it in GitHub Desktop.
Solve Quadratic Equation using Factorization in C++
#include <stdlib.h><br />
#include <iostream.h><br />
#include <math.h><br />
#include <conio.h></p>
<p>void main()<br />
{<br />
cout<<” Quadratic Equation Calculator”<<endl<<” by Ignas<br />
Karve”<<endl<<endl;<br />
float a,b,c,x,y;<br />
cout<<” Equation must be in the form of ax²+bx+c=0″<<endl<<endl;<br />
cout<<” Please enter the value of a: “;<br />
cin>>a;<br />
cout<<” Please enter the value of b: “;<br />
cin>>b;<br />
cout<<” Please enter the value of c: “;<br />
cin>>c;<br />
x=((-b+sqrt((b*b)-(4.0*a*c)))/(2.0*a));<br />
y=((-b-sqrt((b*b)-(4*a*c)))/(2*a));</p>
<p>clrscr();<br />
cout<<“HERE IS THE SOLUTION USING FACTORIZATION</p>
<p>“;<br />
cout.setf(ios::showpos);<br />
float mul=(x*-1)*(y*-1);<br />
cout<<” x²”<<(y*-1)+(x*-1)<<“x”<<mul<<“=0<br />
“;<br />
cout<<” x²”<<y*-1<<“x”<<x*-1<<“x”<<(x*-1)*(y*-1)<<“=0<br />
“; //<br />
x²+2x-1x-2=0<br />
cout<<” x(x”<<y*-1<<“)”<<x*-1<<“(x”<<y*-1<<“)=0<br />
“; // x(x+2)-1(x+2)<br />
cout<<” (x”<<x*-1<<“)(x”<<y*-1<<“)=0</p>
<p>“; // (x-1) (x+2)=0<br />
cout.unsetf(ios::showpos);<br />
cout<<” x=”<<x<<” & x=”<<y<<”<br />
“;<br />
cout<<”</p>
<p> Ignas Laude<br />
laude822@gmail.com”;<br />
exit(EXIT_SUCCESS);<br />
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment