I do not understand why this program gives me wrong result, if anyone can help I would be very appriciated
Code:
#include<stdio.h>
float a,b,c;
float D; // descriminant
float root_1, root_2,sqroot;
void get_quation(void)
{
printf("Enter numbers: a,b,c : \n");
scanf("%f%f%f",&a,&b,&c);
}
float find_descriminant(void)
{
D=b*b-4*a*c;
return D;
}
float absolute_value(float x)
{
if(x<0)
x=-x;
return x;
}
float find_squareroot(float x)
{
const float eplison=.00001;
float guess=1.0;
while(absolute_value(guess*guess-x)>=eplison)
guess=(x/guess+guess)/2.0;
return guess;
}
int main(void)
{
get_quation();
find_descriminant();
if(D>0)
{
sqroot=find_squareroot(D);
root_1=(-b+sqroot)/2*a;
root_2=(-b-sqroot)/2*a;
printf("Square roots is: %f and %f\n", root_1,root_2);
}
else if (D==0)
{
root_1=root_2=-b/2*a;
printf("The root is: \n", root_1);
}
else
{
printf("Roots are imaginary\n");
}
return 0;
}
Thank's in advance