Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 我的方程式一直是零,不知道为什么_C_Equation Solving - Fatal编程技术网

C 我的方程式一直是零,不知道为什么

C 我的方程式一直是零,不知道为什么,c,equation-solving,C,Equation Solving,这是我的全部代码。无论我做什么,我的方程都会一直为零。任何帮助都将不胜感激 #include <stdio.h> #include <stdlib.h> #include <math.h> int main(void) { int x, y; float a,t; //Inputs printf("What is the speed that the jet is traveling in km/hr? \nWhat is the distance trav

这是我的全部代码。无论我做什么,我的方程都会一直为零。任何帮助都将不胜感激

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
int x, y;
float a,t;
//Inputs
printf("What is the speed that the jet is traveling in km/hr? \nWhat is the distance traveled in meters? \n");
scanf("%d , %d", &x, &y );


//Calculations

a = x * 1 / 60 * 1 / 60 * 1 / 60 * 1000 ;

t = sqrt( y * a / 2  ) ;

//Outputs
printf("The acceleration of the jet is %f meters per second squared. \n", a);
printf("The time it takes for the jet to reach takeoff speed is %f seconds. \n", t);

return 0;
}
#包括
#包括
#包括
内部主(空)
{
int x,y;
浮动a,t;
//投入
printf(“喷气机以公里/小时为单位行驶的速度是多少?\n以米为单位行驶的距离是多少?\n”);
scanf(“%d,%d”,&x,&y);
//计算
a=x*1/60*1/60*1/60*1/60*1000;
t=sqrt(y*a/2);
//输出
printf(“射流加速度为%f米/秒平方。\n”,a);
printf(“飞机达到起飞速度所需的时间为%f秒。\n”,t);
返回0;
}

您的第一个等式等于

a = ((((((x * 1) / 60) * 1) / 60) * 1) / 60) * 1000;
ie

即使你的a是一个浮点数,你方程的RHS也在做整数除法


因此,分配给x的任何小于216000的值都将导致0。

x
y
也需要是
float
。您可能需要将整数除法更改为浮点除法。在60后添加一个单点将解决这个问题(
60.
)。@deamentiaemundi不一定,如果(出于某种原因)您想要强制执行整数速度。但不建议使用后者。1/60为0;乘以0,结果为零。使用小数点表示浮点常量:
1.0/60.0
例如(我更喜欢尾随的0;不是每个人都关心)。我在60后添加了小数以表示浮点常量。我现在得到一个输出。谢谢
a = (x/(60*60*60)) * 1000;
a = (x/(216000)) * 1000;