開發平台(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;
}