#include <stdio.h>
int main()
{
int x, y, z1, z2, z3, z5;
float z4;
x = 50;
y = 20;
z1 = x + y;
z2 = x - y;
z3 = x * y;
z4 = (float)x / y;
z5 = x % y;
printf("x+y = %d\n", z1);
printf("x-y = %d\n", z2);
printf("x*y = %d\n", z3);
printf("x/y = %f\n", z4);
printf("x%y = %d\n", z5);
return 0;
}
我运行出的x%y是对的为10,你的程序运行x/y结果是2.00000是因为x除以y的结果为2.5,由于x y都是int型,所以结果也为int型,因此取整为2.00然后赋值给z4,所以z4的输出当然是2.00了。如上面的程序,先把x/y的结果转化为float型,然后赋值,结果就是2.50000了。