gpt4 book ai didi

使用公式速度=距离/时间计算时间

转载 作者:太空宇宙 更新时间:2023-11-04 05:41:08 27 4
gpt4 key购买 nike

用公式speed=distance/time计算时间

但时间总是0我的输入是 distance=10 和 speed=5 我的输出必须 = 2

#include<stdio.h>
int main()
{
int a, b, c, d;
char time, distance, speed;

printf("Enter Your distance ",a);
scanf("%d", &a);
printf("Enter Your speed ",b);
scanf("%d", &b);

time=distance/speed;
printf("time is %d ",time);
}

最佳答案

您使用的是整数(整数算术)而不是 float 。

整数可以是四个字节,但不能包含任何小数(0150035,但不能是3.1251) . float 也是四个字节(大多数情况下),并且确实包含小数点 (3.14),但是, float 的总体范围更小且更难预测。

您还使用了 char(1 个字节)。 1 字节 = 8 位,所以它们的最小值为 -128,最大值为 127。

试试这个:

float time, distance, speed;
time = distance / speed;

关于使用公式速度=距离/时间计算时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932663/

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