I am a beginner c++ programmer and this is my first program.
I enter:
quote:
a=5
b=10
c=5
but it shows
discriminant=-6,9e-018
I thought 10*10-4*5*5=0?
Here my code:
code:
#include <math.h>
#include <stdio.h>
int wortelformule()
{
float a,b,c,d,x1,x2;
printf("ax˛+bx+c=0 \n");
printf("The value of a is ");
scanf("%g",&a);
printf("The value of b is ");
scanf("%g",&b);
printf("The value of c is ");
scanf("%g",&c);
d=pow(b,2)-4*a*c;
printf("\n \nThe discriminant is %g \n",d);
x1=(-b+pow(d,0.5))/(2*a);
x2=(-b-pow(d,0.5))/(2*a);
printf("The first answer is %g \n",x1);
printf("The second answer is %g \n \n",x2);
wortelformule();
}
main()
{
wortelformule();
}