HELP IN C PROGRAM URGENT

Hey Guys,
Am a newbie in programming i have been assignment in school to write and print out the following below;

C program to solve Quadratic equation.

I have one below it is not running it keeps giving me errors.

#include<stdio.h>
void main()
{
float a,b,c,z,d,x,y;
printf("Enter the value of a,b,c");
scanf("%f %f %f",&a,&b,&c);
d=((b*b)-(4*a*c));
z=sqrt(d);
x=(-b+z)/(2*a);
y=(-b+z)/(2*a);
printf("The Quadratic equation is x=%f and y=%f",x,y);

}

Sorry, it's early in the morning. Could you post your error?
1
2
d=((b*b)-(4*a*c)); 
z=sqrt(d);

Cant find any compile errors but d may sometimes b negative and u cant take square root from negative numbers.
1) sqrt() need a prototype header file, viz. <math.h>
2) Put a check for d<0, coz as Breadman said, d should not be negative, else your program will crash at run-time.
3) Both your roots are same. It should be:

1
2
x=(-b+z)/(2*a);
y=(-b-z)/(2*a);
Topic archived. No new replies allowed.