[英]I keep getting zero from my equations and do not know why
Here is my full code.这是我的完整代码。 I keep getting zero for my equations no matter what i do.
无论我做什么,我的方程都一直为零。 Any help would be greatly appreciated.
任何帮助将不胜感激。
#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;
}
Your first equation is equivalent to你的第一个方程等价于
a = ((((((x * 1) / 60) * 1) / 60) * 1) / 60) * 1000;
ie; IE;
a = (x/(60*60*60)) * 1000;
or或者
a = (x/(216000)) * 1000;
Even though your a is a float, RHS of your equation is doing integer division.即使你的 a 是一个浮点数,你的方程的 RHS 也在做整数除法。
Hence any value less than 216000 assigned to x will result in 0.因此,分配给 x 的任何小于 216000 的值都将导致 0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.