#include <stdio.h> int Disk(int num) { int ans = 0; if(num <= 0){ ans-=1; }else if(num == 1){ ans = 1; }else{ ans = 2*Disk(num-1) + 1; } return ans; } void main() { int num = 0; printf("請輸入盤子數量:"); scanf("%d",&num); printf("移動%d個盤子,需要移動%d次\n",num,Disk(num)); }