I am studying logic building with C, I just write a small code about equation. Here is the code:
#include<stdio.h>
int main()
{
float a,b;
printf("Find solutions for equation: aX + b = 0\n");
printf("Input value for a: ");
scanf("%f", &a);
printf("Input value for b: ");
scanf("%f", &b);
if(a == 0)
{
if (b ==0)
{
printf("Countless solution.");
}
else
{
printf("Have no solution.");
}
}
else
{
printf("Have one solution: x = %.2f", -b/a);
}
}
The problem is when I input a=any number, b=0, I have solution is: x= -0.00.
I don't understand why it is x = -0.00
instead of x = 0.00
?
I have tested cases a==0 && b==0
, a==0 && b!=0
and it works fine.
I am confusing about this. Can anyone explain to me?