#include <stdio.h>  
#include <math.h>
#include <string.h>
                             
struct qroots {
float x1;
float x2; };

int errno=0;

struct qroots quadratic (float a, float b, float c) {
    float d;
    struct qroots roots;
    roots.x1=-1;
    roots.x2=-1;
    if (a==0) {errno=-2; return roots;}
    d=b*b-4*a*c;
    printf ("The discriminant of the quadratic equation has a value of %f\n",d); 
    if (d<0) { errno=-1; return roots; }
    if (d==0) {
        roots.x1=(-b)/(2*a); 
        roots.x2=roots.x1;
        return roots; }
   if (d>0) {
       roots.x1=(-b+sqrt(d))/(2*a);
       roots.x2=(-b-sqrt(d))/(2*a);
       return roots; }}
   

int main (void) {
    struct qroots R;
    float a, b, c;
    printf ("Solving the quadratic equation ax^2+bx+c=0\n");
    printf ("Give the value of a: ");
    scanf ("%f",&a);
    printf ("Give the value of b: ");
    scanf ("%f",&b);
    printf ("Give the value of c: ");
    scanf ("%f",&c);
    R = quadratic (a,b,c); 
    if (errno==-2) printf("Equation is not quadratic\n");
    else if (errno==-1) printf ("The quadratic equation has no real roots\n");
    else printf ("The two roots of the quadratic equation are x1=%f and x2=%f\n",R.x1, R.x2);  
    return (0); }


