C语言 输出不为真

ca1c2owp  于 2023-01-20  发布在  其他
关注(0)|答案(1)|浏览(172)

下面是我的代码:

#include <stdio.h>

int main()
{
    int inches = 0; 
    int yards = 0;
    int feet = 0;
    const int inches per foot = 12;
    const int feet_per yard = 3;
    printf("Enter a distance in inches: ");
    scanf ("%d", &inches);
    feet = inches/inches_per_foot;
    yards = feet/feet_per_yard; feet %= feet_per_yard;
    inches %= inches_per_foot;
    printf("That is equivalent to %d yards %d feet and %d inches.\n",      
    printf("or %d centimeters\n", inches*2.54);
}

输入:输入距离(英寸):10
产量:相当于0码0英尺10英寸,或1717986918厘米。
那么,1717986918是什么?

g0czyy6m

g0czyy6m1#

那么,1717986918是什么?
这是当你试图打印一个double时发生的事情,就好像它是一个int一样。

printf("or %d centimeters. \n", inches *2.54);

由于inches *2.54涉及与浮点数相乘,因此inches隐式转换为double,结果为double。使用%f打印double

printf("or %f centimeters. \n", inches *2.54);

相关问题