這個簡單的代碼有點問題。C中的雙值錯誤
我已經嘗試過不同類型的鑄件,但是我在這裏沒有任何問題。如果有人告訴我爲什麼總是打印0.0000000或類似的原因,我會提前感到遺憾和感謝。
#include<stdio.h>
main()
{
double num1,num5;
printf ("Hello user\n");
printf ("Let the thickness of black and white brick are same and the value
is 2m\nAnd the gap between them is 1m\n");
printf ("\nEnter the length of the road:\n");
scanf ("%lf",&num1);
num5 = ((2/5)*num1);
printf ("%lf",num5);
return 0;
}
重複與https://stackoverflow.com/questions/40443602/c-double-not-working-as-expect/40443639# 40443639和https://stackoverflow.com/questions/16221776/why-dividing-two-integers-doesnt-get-a-float –
[分隔1/n總是返回0.0](https://stackoverflow.com/questions/13331054/divide-1-n-always-returns-0-0) –