菜鸟求助,强制类型转换的有关问题,大虾们帮帮忙啊!
#include<stdio.h>int main(void)
{
int a,b;
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
if(b) printf("%d\n",a/b);
else printf("Cannot divide by zero.\n");
return 0;
}
源程序如上,不能显示小数部分,修改如下
#include<stdio.h>
int main(void)
{
int a,b;
printf("Enter two numbers:");
scanf("%d%d",&a,&b);
if(b) printf("%d\n",(float)a/b);
else printf("Cannot divide by zero.\n");
return 0;
}
结果显示不正确结果了,大虾们帮帮忙找找原因,谢谢了!