clc
clear

%this program solves the equation a*x^2+b*x+c=0
a = input('Enter a coefficient of 2nd order equation: \n');
b = input('Enter b coefficient of 2nd order equation: \n');
c = input('Enter c coefficient of 2nd order equation: \n');

Delta = b^2 - 4*a*c;
if Delta > 0
    x1 = (-b + sqrt(Delta))/ (2*a);
    x2 = (-b - sqrt(Delta))/ (2*a);
    fprintf('The roots of the equation are: \n %f \t %f \n',x1,x2);
    x=[-10:0.1:10];
    y=a*x.^2+b*x+c;
    plot(x,y,x1,0,'go',x2,0,'go')
    grid
end
if Delta == 0
    x1 = (-b)/ (2*a);
    fprintf('The single root of the equation is: \n %f',x1);
    x=[-10:0.1:10];
    y=a*x.^2+b*x+c;
    plot(x,y,x1,0,'go')
    grid
end
if Delta < 0
    fprintf('There is no real root. \n')
    x=[-10:0.1:10];
    y=a*x.^2+b*x+c;
    plot(x,y)
    grid
end
