Quote:
I used else if statement to print integer when needed. It worked for two conditions but it's not working for the third condition. The code I wrote is given below.
Because your code says so:
#include<stdio.h>
int main(){
int a,b,c,d,e, about;
double x,y,z, sum;
double i, j;
for(i=0; i<2; i=i+0.2){
for(j=1; j<=3; j++){
if(i==0.0){
printf("%.0lf %.0lf\n", i, j+i);
}else if(i==1.0){
printf("%.0lf %.0lf\n", i, j+i);
}else if(i==2.0){
printf("%.0lf %.0lf\n", i, j+i);
}else{
printf("%.1lf %.1lf\n", i, j+i);
}
}
}
return 0;
}
[Update]
Quote:
1st two outputs are integers... But the third printf is printing float... that's why I am telling that third statement is not working.
Stop guessing, make sure, try with this code.
if(i==0.0){
printf("A %.0lf %.0lf\n", i, j+i);
}else if(i==1.0){
printf("B %.0lf %.0lf\n", i, j+i);
}else if(i==2.0){
printf("C %.0lf %.0lf\n", i, j+i);
}else{
printf("D %.1lf %.1lf\n", i, j+i);
}
}
}
return 0;
}
Use the letter in each printf to distinguish which printf was used.
Ur learn debugger.