Determine the roots of the quadratic equation
ax2 + bx + c = 0
using the formula of quadratic equation
PROGRAM:
#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
void main() {
clrscr();
double a,b,c,d;
cout<<"Enter the values of A, B and C for the given quadratic equation";
cout<<"\nEnter value A: ";
cin>>a;
cout<<"\nEnter value B: ";
cin>>b;
cout<<"\nEnter value C: ";
cin>>c;
if(sqrt(pow(b,2)-(4*a*c)<0)) {
cout<<"\ndeterminant is less than 0, \nroots of the quadratic equation cannot be found";
getch();
exit(0);
}
d=sqrt(pow(b,2)-(4*a*c));
cout<<"\nThe roots of the quadratic equation are: \n";
cout<<"\nRoot 1: "<<-b+d/(2*a);
cout<<"\nRoot 2: "<<-b-d/(2*a);
getch();
}//end of the program
No comments:
Post a Comment