Here is the code I am trying to run.
int main() {
double dx=0.1, p=-10;
double x[200];
int i=0;
while (p<=10) {
if (p==0) {
p=p+dx;
}
x[i]=p;
i++;
p=p+dx;
}
for (i=0; i<200; i++) {
printf("%lf ", x[i]);
}
return 0;
}
I want the array x to contain numbers from -10 to 10 with an increment of 0.1 but excluding zero. However, this program is saving -0.0 in the array x[]. The if condition is coming out to be false for some reason. The program works for an increment of 0.25.
How can I change this code for a 0.1 increment?