Can you please help me by explaining why my code isn't working? In the last part, 2 doesn't get printed..Rather 1 gets printed.. See the comment in the code. If I change to that , 2 comes as double. I don't know why. CODE: #include
int main() {
double i, j;
int a, b;
for(i = 0.0 ; i < 2.1 ;i = i + 0.2) { if(i == 0.0 || i==1.0 || i > 1.8 )//here if we give i==2.0 instead of i>1.8..Se the change { a = i ; for(b = 1 ;b <= 3; b++) { printf("I=%d J=%d\n", a, a + b); } } else { for(j = 1.0 ; j <= 3.0 ; j++) { printf("I=%.1lf J=%.1lf\n", i, i+j); } } } return 0; }
Can you please help me by explaining why my code isn't working? In the last part, 2 doesn't get printed..Rather 1 gets printed.. See the comment in the code. If I change to that , 2 comes as double. I don't know why.
ReplyDeleteCODE:
#include
int main()
{
double i, j;
int a, b;
for(i = 0.0 ; i < 2.1 ;i = i + 0.2)
{
if(i == 0.0 || i==1.0 || i > 1.8 )//here if we give i==2.0 instead of i>1.8..Se the change
{
a = i ;
for(b = 1 ;b <= 3; b++)
{
printf("I=%d J=%d\n", a, a + b);
}
}
else
{
for(j = 1.0 ; j <= 3.0 ; j++)
{
printf("I=%.1lf J=%.1lf\n", i, i+j);
}
}
}
return 0;
}