搜索
查看: 1407|回复: 4
打印 上一主题 下一主题

取小数函数的问题

[复制链接]
跳转到指定楼层
楼主
发表于 2013-3-3 16:30:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
float tdec(float a);
#include <stdio.h>
#include <stdlib.h>
main()
{
float b,c;
scanf("%f",&b);
c=tint(b);
printf("%f",c);

system("pause");
return 0;
}
float tdec(float a);
{
while(a>1)
{ a--;
}
while(a<1)
{ a++;
}
return a;
}[code=Cpp width=740px][/code]

最佳答案

查看完整内容

14行后面多了个分号 另外这函数逻辑处理上也是有问题的 比如tdec(1.5) 就会先减一,再加一,最后返回1.5
沙发
发表于 2013-3-3 16:30:38 | 只看该作者
14行后面多了个分号

另外这函数逻辑处理上也是有问题的
比如tdec(1.5)
就会先减一,再加一,最后返回1.5
板凳
发表于 2013-3-3 21:03:09 | 只看该作者
c=tint(b);

这一行函数名写错了吧

取小数部分可以这么写
  1. float fun(float a)
  2. {
  3.     return a-(int)a;
  4. }
复制代码
地板
 楼主| 发表于 2013-3-10 13:27:03 | 只看该作者
改掉了,还不对[code=Cpp width=740px]float tdec(float a);
#include <stdio.h>
#include <stdlib.h>
main()
{
float b,c;
scanf("%f",&b);
c=tdec(b);
printf("%f",c);

system("pause");
return 0;
}
float tdec(float a);
{
while(a>1)
{ a--;
}
while(a<1)
{ a++;
}
return a;
}
[/code]
5#
 楼主| 发表于 2013-3-17 14:54:15 | 只看该作者
谢谢,解决了
[code=AS3 width=740px]float tdec(float a);
#include <stdio.h>
#include <stdlib.h>
main()
{
float b,c;
scanf("%f",&b);
c=tdec(b);
printf("%g",c);

system("pause");
return 0;
}
float tdec(float a)
{ int a0=a;
while(a>1)
{ a--;
}
while(a<1)
{ a++;
}
if(a0>0)
return a-1;
if(a0<0)
return -(2-fabs(a));
}
[/code]
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表