THIS A CODE TO PRINT ROOTS OF QUADRATIC EQN USING FUNCTIONS ... NOT WORKING!!

#include <math.h>

#include <stdio.h>

int

main ()

{

int a, b, c;

float D;

int x;

printf ("enter the co-effecients of the equation : ");

scanf ("%d %d %d", &a, &b, &c);

D=ROOTS(a,b,c);

printf("%f",D);

if (D > 0)

{

printf ("\nthe roots are distinct and real \nroot 1 %.0f\nroot 2 %.0f",

(-b + D) / (2 * a), (-b - D) / (2 * a));

}

else if (D == 0)

{

printf ("\nthe roots are real and equal \nroot 1 %.0f\nroot 2 %.0f",

-b / (2 * a), -b / (2 * a));

}

else if (D < 0)

{

printf ("\nno real roots");

}

return 0;

}

int ROOTS(int l,int  m, int n)

{

double E;

E = sqrt ((m * m) - (4 * l * n));

return(E);

}

+1 vote
answered Jan 25 by (69,270 points)

You are using various types all around: int, float, double.

For instance, in your ROOTS function you force the value to be returned as an integral number, losing all the decimal values.

When you print out the results, you tell the compiler to not print any decimal digits.

```#include <math.h>
#include <stdio.h>

float ROOTS(int l, int m, int n)
{
return sqrt ((m * m) - (4 * l * n));
}

int main ()
{
int a, b, c;
printf("enter the co-effecients of the equation : ");
scanf("%d %d %d", &a, &b, &c);
float D = ROOTS(a, b, c);
printf("D: %f", D);
if (D > 0)
{
printf("\nthe roots are distinct and real \nroot 1 %f\nroot 2 %f", (-b + D) / (2.0f * a), (-b - D) / (2.0f * a));
}
else if (D == 0)
{
printf("\nthe roots are real and equal \nroot 1 %f\nroot 2 %f", -b / (2.0f * a), -b / (2.0f * a));
}
else if (D < 0)
{
printf ("\nno real roots");
}
return 0;
}```