啊哈磊_编程从这里起步
标题:
取小数函数的问题
[打印本页]
作者:
981013
时间:
2013-3-3 16:30
标题:
取小数函数的问题
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]
作者:
rosynirvana
时间:
2013-3-3 16:30
14行后面多了个分号
另外这函数逻辑处理上也是有问题的
比如tdec(1.5)
就会先减一,再加一,最后返回1.5
作者:
rosynirvana
时间:
2013-3-3 21:03
c=tint(b);
这一行函数名写错了吧
取小数部分可以这么写
float fun(float a)
{
return a-(int)a;
}
复制代码
作者:
981013
时间:
2013-3-10 13:27
改掉了,还不对[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]
作者:
981013
时间:
2013-3-17 14:54
谢谢,解决了
[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]
欢迎光临 啊哈磊_编程从这里起步 (https://bbs.codeaha.com/)
Powered by Discuz! X3.2