0
The return of the code below is "-Nan", and I am not identifying the error.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
struct variaveis
{
float a,b,c;
};
float delta (float a, float b, float c){
float a1=a,b1=b,c1=c;
a1 = pow(b1,2) - 4*a1*c1;
return a1;
}
float x1 (float a,float b,float c){
float a1 = a, b1=b, c1=c;
printf("x1 = %f\n", (b*-1 + sqrt(delta(a,c,b)))/2*a);
}
float x2(float a, float b, float c){
float a1=a,b1=b,c1=c;
printf("x2 = %f\n", (b1*-1 - sqrt(delta(a1,b1,c1)))/2*a1);
}
int main(){
float a, b, c;
scanf("%f %f %f", &a, &b, &c);
x1(a,b,c);
x2(a,b,c);
return 0;
}
Your program only calculates real roots. Check if delta is negative and, in this case, calculate the imaginary roots of your equation (a+b*i) or report that it has no roots in the real field.
– anonimo
It’s always best to use
double
(*) when floating comma values are desired. (*) Remember to fix scanfs– pmg