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

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



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 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<

One thought on “Quadratic (second-degree) equation in C++ (CPP)

  1. Pingback: Retrospectiva săptămânii #2 : Cristi Juverdeanu

Leave a Reply

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