Quantcast
Viewing all articles
Browse latest Browse all 10

Quadratic (second-degree) equation in C++ (CPP)

A quadratic or second degree equation has the following mathematical syntax:

Image may be NSFW.
Clik here to view.
1c110885bd9155bea6b6630e7d24d6c4[1]

 

where x is the variable, and a,b,c are user defined constant numbers.

The following code will solve the quadratic equation and will return the solution if the results are integers:


#include

#include
int a,b,c,x1,x2,delta;
void main()
{ cin>>a; cin>>b; cin>>c;
delta = b*b-4*a*c;
if (delta<0) cout<<”The solution is not an integer”; else { x1=(-b+sqrt(delta))/(2*a); x2=(-b-sqrt(delta))/(2*a); cout<< x1<

The post Quadratic (second-degree) equation in C++ (CPP) appeared first on BorlandC.org.


Viewing all articles
Browse latest Browse all 10

Trending Articles