首页 > 编程语言 > 详细

在C语言中除法运算为什么没有小数部分?

时间:2015-07-14 15:30:14      阅读:486      评论:0      收藏:0      [点我收藏+]

 


原文链接: http://wenda.tianya.cn/question/4e096f010317a93d

除法运算符" / ",如果是两个整数相除结果为整数
如果需要保留小数时 必须将其中一个除数转换为浮点数

#include <stdio.h>
#include <math.h>
main()
{
float x;
float y;
printf("Enter x:");
scanf("%d",&x);
y=fabs((5*x+1)/(x*x+1));
printf("y is %f\n",y);
}

或者

#include <stdio.h>
#include <math.h>
main()
{
int x;
float y;
printf("Enter x:");
scanf("%d",&x);
y=fabs((float)(5*x+1)/(x*x+1));
printf("y is %f\n",y);
}

 

 

 

 

在C语言中除法运算为什么没有小数部分?

原文:http://www.cnblogs.com/huhu0013/p/4645378.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!