[問題] pow無法求出2的冪次方
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) C
問題(Question):
無法求出2的冪次方
餵入的資料(Input):任意正整數 or 0
預期的正確結果(Expected Output):輸入任何大於或等於零的整數,皆可以算出值
錯誤結果(Wrong Output):編譯上好像有錯誤,輸入任何值的結果都會使得輸出為零
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int fac(int n)
{
if (n<0)
printf("Error!");
else
return pow(2,n);
}
int main()
{
int x;
printf("請輸入指數x的值:");
scanf("%d",&x);
printf("x=%d,此時2的x次方為%d\n",x,fac(x);
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.133.57.54
※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1408761369.A.267.html
→
08/23 10:51, , 1F
08/23 10:51, 1F
→
08/23 10:52, , 2F
08/23 10:52, 2F
阿 眼殘 我真的少了個右括號= = 感謝
順便請教一下 如果我要把副程式放到主程式後面宣告的話
那主程式該怎麼做修正?
還是C語言不能把副程式放在後面?
→
08/23 11:10, , 3F
08/23 11:10, 3F
→
08/23 11:11, , 4F
08/23 11:11, 4F
→
08/23 11:11, , 5F
08/23 11:11, 5F
→
08/23 11:12, , 6F
08/23 11:12, 6F
試過了 確實可以編譯成功 感謝各位
※ 編輯: gauss760220 (220.133.57.54), 08/23/2014 11:17:09
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章