在C语言中有没有什么样的方法能求出一个小数的小数部分

;例如在输入2.33后,给我输出0.33有谁能帮帮我写下程序谢谢啦我所需要的是可以输入一个数,小数型的,输出这个数的小数部分... ;例如在输入2.33后,给我输出0.33
有谁能帮帮我写下程序
谢谢啦
我所需要的是可以输入一个数,小数型的,输出这个数的小数部分
展开
 我来答
飞飞1930
2008-11-16 · TA获得超过817个赞
知道小有建树答主
回答量:269
采纳率:0%
帮助的人:367万
展开全部
a-=(int)a;
(int)a将a强制转换为正整数,直接舍弃小数部分。
执行上面的a-=(int)a; 得到的a不就是原来的小数部分么?
我说的明白?
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
惠阶平
2008-11-15
知道答主
回答量:59
采纳率:0%
帮助的人:0
展开全部
先把这个float型的数强制转换为int型,再用原来的float数减去这个int数即可,如:
float a=3.14 ,int b,c;
b=(int)a;
c=a-b;
c即为所求的数
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
dielsalder
2008-11-15 · TA获得超过3855个赞
知道大有可为答主
回答量:1864
采纳率:50%
帮助的人:2903万
展开全部
http://www.cplusplus.com/reference/clibrary/cmath/modf.html

double modf ( long double x, long double * intpart );
long double modf ( long double x, long double * intpart );
float modf ( float x, float * intpart ); <cmath>

Break into fractional and integral parts

Breaks x into two parts: the integer part (stored in the object pointed by intpart) and the fractional part (returned by the function).

Each part has the same sign as x.

Parameters
x
Floating point value.
intpart
Pointer to an object where the integral part is to be stored.

Return Value
The fractional part of x, with the same sign.

Portability
In C, only the double version of this function exists with this name.

Example
/* modf example */
#include <stdio.h>
#include <math.h>

int main ()
{
double param, fractpart, intpart;

param = 3.14159265;
fractpart = modf (param , &intpart);
printf ("%lf = %lf + %lf \n", param, intpart, fractpart);
return 0;
}

Output:

3.141593 = 3.000000 + 0.141593
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
CX3201
2008-11-15 · TA获得超过157个赞
知道小有建树答主
回答量:355
采纳率:0%
帮助的人:0
展开全部
a = a - int(a);
a是float没错啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式