c语言 去掉小数点后面的数

用程序处理 比如123.123 变成123, 谢谢了

有两种方法:

    使用函数:

    #include<stdio.h>

    void main()

    { double x,temp; int a; scanf("%lf",&x);

    temp=x; a=int(temp);

    while(a!=temp

    { temp=temp*10; a=int(temp);

    } printf("%d\n",a); }

    2.使用强制转换命令:(int)f;

注意:在转换的时候,前面的转换型一定要打括号,否则不起作用。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-03-23
f=123.123
使用强制转换命令:(int)f;
注意:在转换的时候,前面的转换型一定要打括号,否则不起作用。本回答被提问者采纳
第2个回答  2009-03-23
太简单了
#include"stdio.h"
main()
{
float m;
scanf("%f",&m); //输入小数
printf("%.0f",m); //去掉小数点后面的数
}
第3个回答  2009-03-23
double a=123.123;
printf("%d",int(a));
第4个回答  2009-03-23
#include <stdio.h>

void main()
{
printf("%d",int(123.123));
}