gpt4 book ai didi

C编程与计算

转载 作者:太空宇宙 更新时间:2023-11-04 06:29:43 24 4
gpt4 key购买 nike

<分区>

今天我尝试制作一个将距离转换为米、英寸等的计算器。我使用 Visual Studio 2013 Ultimate 用 C 语言编写了我的小程序。

我的问题是,当我输入数字时程序计算错误!

附言。这不是家庭作业,而是我正在 ATM 阅读的“让我们 C”中的练习。

我得到以下输出:

Enter values of the distance between the two cities in km's10 Meter=0 inch=-1064763392 feet=-2147483648 cm=1103731097 Waiting for a character to be pressed from the keyboard to exit.

/*Just for fun Author: Anru*/
#include <stdio.h>
int main()
{
int km;
float result_met, result_inch, result_feet, result_cm;

/*Display text*/
printf("Enter values of the distance between the two cities in km's");
scanf_s(&km);

/*Formular for a simple km conversion*/

result_met = km * 1000;
result_inch = km * 39370;
result_feet = km * 3280;
result_cm = km * 100000;

/*Result print*/
printf("Meter=%d\ninch=%d\nfeet=%d\ncm=%d",result_met, result_inch, result_feet, result_cm);

printf("\nWaiting for a character to be pressed from the keyboard to exit.\n");

getch();

return 0;
}

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