#include<stdio.h>
#define MM 40
main()
{
int a=3,b=6;
float t;
t=MM/(a+b);
printf("t=%f MM=%d\n",t,MM);
}
法1,定义a,b为float
法2,强制转换 t=(float)MM/(a+b);
t=MM/(float)(a+b);
a, b 定义为 float 类型
t = (float)MM / (a + b);
改成这样就好啦
#include <stdio.h>
#define MM 40
main()
{
float a = 3, b = 6;
float t;
t = MM / (a + b);
printf("t=%f MM=%d\n", t, MM);
}