F
fb
Hello everyone. I'm having a touch of trouble solving a problem using
the quadratic formula. I get a domain error...Somewhere in the sqrt
function I think. Could you guys give me a hint on what's up? Is there
maybe some kind of standard Quadratic function hiding away in the
libraries? That would be nice to have...Here's my source:
/* Trying to calculate the real roots of "ax^2 + bx + c = 0"
using the quadratic formula */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
double a, b, c, d, x1, x2;
/* read input data */
printf("a = ");
scanf("%f", &a);
printf("b = ");
scanf("%f", &b);
printf("c = ");
scanf("%f", &c);
/* Carry out the calculations */
d = sqrt(b*b-4*a*c);
x1 = (-b + d) / (2 * a);
x2 = (-b - d) / (2 * a);
/* Display output */
printf("\nx1 = %e x2 = %e", x1, x2);
return EXIT_SUCCESS;
}
the quadratic formula. I get a domain error...Somewhere in the sqrt
function I think. Could you guys give me a hint on what's up? Is there
maybe some kind of standard Quadratic function hiding away in the
libraries? That would be nice to have...Here's my source:
/* Trying to calculate the real roots of "ax^2 + bx + c = 0"
using the quadratic formula */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
double a, b, c, d, x1, x2;
/* read input data */
printf("a = ");
scanf("%f", &a);
printf("b = ");
scanf("%f", &b);
printf("c = ");
scanf("%f", &c);
/* Carry out the calculations */
d = sqrt(b*b-4*a*c);
x1 = (-b + d) / (2 * a);
x2 = (-b - d) / (2 * a);
/* Display output */
printf("\nx1 = %e x2 = %e", x1, x2);
return EXIT_SUCCESS;
}