To write a program to calculate the roots of a quadratic equation ie ax^2+bx+c=0

Provided three coefficients a, b & c; this program can calculate the roots of a quadratic equation ie ax^2+bx+c=0.
Simply check the code (we encourage you NOT to copy paste this code to the editor) below with the one you wrote yourself.
For the complete lab report including background theory, algorithm, flow chart, along with full downloadable pdf document, please go here.
/************************************************
SUBJECT : NUMERICAL METHODS
LAB 1: TO FIND THE ROOTS OF QUADRATIC EQUATIONS
BRIEF ALGORITHM:
1.START
2.INPUT COEFFICEINTS- A,B ,C
3.COMPUTE DETERMINANT- D
4.CHECK IF D IS REAL OR IMAGINERY
…..
…..
…..
5.STOP
*************************************************/
#include
#include
#include
#include
void main()
{
//defining variables
float A,B,C;
float D;
clrscr(); //clearing the screen if previously loaded
cout<<“Enter the coefficients A, B, C\n”;
cin>>A>>B>>C;
D=(B*B-4.0*A*C);
cout<<“\nFine, the determinant D= ” <
if (D>=0)
{
cout<<“\n\nThe roots are REAL.”;
double X1=(-B+sqrt(D))/(2.0*A);
double X2=(-B-sqrt(D))/(2.0*A);
cout<<“\n\t”<<< “\n\t”<
}
else
{
cout<<“\n\nThe roots are COMPLEX.”;
double RealPart= -B/(2.0*A);
double ImagPart= -sqrt(abs(D))/(2.0*A);
cout<<“\n\t”<<< “\n\t”<
}
cout<<“\n\n\nWritten in C++; Thank you”;
getch();
}
To write a program to calculate the roots of a quadratic equation ie ax^2+bx+c=0 in C++ Programming Language for Numerical Methods for Engineering Students

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top