gpt4 book ai didi

c - 这段c代码有什么问题?答案总是零?

转载 作者:行者123 更新时间:2023-11-30 21:45:52 25 4
gpt4 key购买 nike

我是c语言新手,请帮忙,这个问题的答案总是零。为什么?而不是将 KM 转换为米或厘米(抱歉拼写错误);

#include <stdio.h>

int main()
{
float Km;
float metres;
float inches;
float centimetres;

printf("Welcome, please enter the distance in Km.\n");

scanf("%f", &Km);
metres = Km * 1000;
centimetres = Km*100000;
inches = Km*25/1000000;

printf("Distance In Metres is:\n");
printf("%f\n", &metres);

printf("Distance in Centimeters is:\n");
printf("%f\n", &centimetres);

printf("Distance in Inches is:\n");
printf("%f\n", &inches);

printf("bye\n");

return 0;
}

最佳答案

printf 函数写入变量的值。 & 运算符 & 将您的值转换为指针,这就是错误。您不是打印变量的实际值,而是打印指针的地址内存。

阅读documentation关于 printf 函数。有关 &* 的更多信息 here .

关于c - 这段c代码有什么问题?答案总是零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45335183/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com