To solve any coordinate equations

Question - 
Given any coordinate equation , you have to solve that equation.

Example -
Input : a = 1, b = 5 , c = 4
Output : x1= -1 , x2= -4

Input : a = 1 , b = 0 , c = -1
Output : x1= -1 , x2 = 1

Approach - 
We solve this question with the help of shri dharacharya formulas.

Implementation -
 
//To solve the coordinte equation
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a,b,c;
    double d;
    cout<<"A coordinte equation is represented as : a*x^2 + b*x + c = 0"<<endl;
    cout<<"Enter the value of a : ";cin>>a;
    cout<<"Enter the value of b : ";cin>>b;
    cout<<"Enter the value of c : ";cin>>c;
    d=sqrt((b*b)-4*a*c);
    double x1,x2;
    x1=(-b+d)/(2*a);
    x2=(-b-d)/(2*a);
    cout<<"x1 = "<<x1<<endl<<"x2 = "<<x2<<endl;
}

Time complixity - O(1)

Comments