Created
May 21, 2014 08:58
-
-
Save Manume/067ec0ee4db01ff70eb7 to your computer and use it in GitHub Desktop.
roots of a quadratic equation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream.h> | |
| #include <conio.h> | |
| #include <math.h> | |
| int main() | |
| { | |
| clrscr(); | |
| float a,b,c,d,root1,root2; | |
| cout << "Enter the 3 coefficients a, b, c : " << endl; | |
| cin>>a>>b>>c; | |
| if(!a){ | |
| if(!b) | |
| cout << "Both a and b cannot be 0 in ax^2 + bx + c = 0" << "\n"; | |
| else | |
| { | |
| d=-c/b; | |
| cout << "The solution of the linear equation is : " << d << endl; | |
| } | |
| } | |
| else | |
| { | |
| d=b*b-4*a*c; | |
| if(d>0) | |
| root1=(-b+sqrt(d))/(2*a); | |
| root2=(-b-sqrt(d))/(2*a); | |
| cout << "The first root = " << root1 << endl; | |
| cout << "The second root = " << root2 << endl; | |
| } | |
| getch(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment