拆分实数的整数与小数部分[C语言]
#include <stdio.h> void splitfloat(float x, int *intpart, float *fracpart){ *intpart = (int) x; *fracpart = x - *intpart; } int main(void){ float number = 1.662; int a; float b; splitfloat(number, &a, &b); printf("intpart = %d, fracpart = %f", a, b); return 0; }