How to extract the decimal part from a floating point number in C?

后端 未结 14 2041
旧巷少年郎
旧巷少年郎 2020-11-27 04:04

How can we extract the decimal part of a floating point number and store the decimal part and the integer part into two separate integer variables?

14条回答
  •  猫巷女王i
    2020-11-27 04:53

    Even I was thinking how to do it. But I found a way. Try this code

    printf("Enter a floating number");
    scanf("%d%c%d", &no, &dot, &dec);
    printf("Number=%d Decimal part=%d", no, dec);
    

    Output:-

    Enter a floating number
    23.13
    Number=23 Decimal part=13
    

提交回复
热议问题