拆分实数的整数与小数部分[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;
}

 

posted @ 2021-09-15 16:19  就是想学习  阅读(855)  评论(0编辑  收藏  举报