老瘋君 發表於 2009-12-19 16:22

河內塔

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

void hanoi(int 盤數,int 初,int 補,int 終){

if(盤數==1)

printf("%d>%d\n",初,終);

else{

hanoi(盤數-1,初,終,輔);

printf("%d>%d\n",初,終);

hanoi(盤數-1,輔,初,終);

}
}

int main(){


int 盤;


srand(time(NULL));

盤=rand()%;


printf("柱一=1,柱二=2,柱三=3\n盤數=%d\n",盤);


hanoi(盤數,1,2,3);


system ("pause");

return 0;
}
頁: [1]
查看完整版本: 河內塔