int c, f;
f=(int)((9.0/5)*c+32);
for(c=0;c<=50;c+=10)
printf("c=%d f=%d\n",c,f);
return0;
I squeezed it out, but 9.0/5 keeps coming out as zero
c++
Try it as below.
float f = 9.0/5;
printf("f=%f\n", f);
intc, f;
f=(int)((9.0/5)*c+32);
for(c=0;c<=50;c+=10)
printf("c=%d f=%d\n",c,f);
return0;
First of all, when putting the value in f, c is not initialized by the user The default value of c is 0, so f must be 32 in the printf statement.
intc{}, f{};
for(c=0;c<=50;c+=10) {
f=(int)((9.0/5)*c+32);
printf("c=%d f=%d\n",c,f);
}
And %d gets an int-type decimal. Then, the decimal point is naturally truncated, so if you want to express the decimal point, write %f.
© 2024 OneMinuteCode. All rights reserved.