2016-09-28 25 views
-2

这是我的完整代码。无论我做什么,我都会为我的方程得到零。任何帮助将不胜感激。我一直从我的等式中得到零,不知道为什么

#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; 
} 
+1

'x'和'y'需要是'float',太。 – deamentiaemundi

+0

您可能想要将整数除法改为浮点除法。在60年代之后添加一个点会照顾那个('60.')。 – Evert

+0

@deamentiaemundi不一定,如果(由于某种原因)你想强制整数速度。后者虽然不被推荐。 – Evert

回答

0

你的第一等式是等效于

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

即;

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

a = (x/(216000)) * 1000; 

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

因此赋值给x的任何值小于216000将导致0

相关问题