如:「2 3」,計算出「8」
本次使用了許多「如果」及「迴圈」,應注意邏輯觀念,以便於程式設計
#include <stdio.h>
int main () {
int a,n,x=0,answer,answer1;
printf("Enter base and exponent: "); //請輸入底數與指數
if (n>0) {
answer=a;
while(x<n-1) {
answer1=answer*a;
answer=answer1;
x++;
}
printf("Answer: %d",answer);
}
else if (n==0) {
if (a==0) {
printf("Error");
}
else {
answer=1;
printf("Answer: %d",answer); //顯示答案為1
}
}
return 0;
}