代碼如下,結果輸入了之後完全沒有輸出,完全不清楚什麼狀況,求解!!!
#include
#include
#include
#include
float x,y,z;
float InvSqrt(float x)
{
float xhalf = 0.5f*x;
int i = (int)&x;
i = 0x5f3759df - (i >> 1);
x = (float)&i;
x = x*(1.5f - xhalf*x*x);
return x;
}
float count_1()
{
clock_t s1 = clock();//開始時間
float i = 1 / sqrt(x);
clock_t e1 = clock();//開始時間
printf("%.2f s\n", ((float)e1 - s1) / CLOCKS_PER_SEC);
return 0;
}
float count_2()
{
clock_t s2 = clock();//開始時間
float i = InvSqrt(x);
clock_t e2 = clock();//開始時間
y = s2 - e2;
printf("%.2f s\n", ((float)e2 - s2) / CLOCKS_PER_SEC);
return 0;
}
void main() {
printf("請輸入一個值");
scanf_s("%f", &x);
float count_1();
float count_2();
system("pause");
}
float count_1();
float count_2();
你這是在聲明函數,不是調用函數,函數沒調用自然沒有輸出!
count_1(); //這樣才是調用函數