我们c语言结课,做结课设计。做汉诺塔。网上找了个程序,改了一下,就差在任意情况下按esc退出不会弄了。麻烦高手帮我在我的程序上改一个esc退出,谢谢~~~~是在我的程序上改,不是网上找个那个while的死循环程序复制上来,改好了100分一定会给的,帮个忙,十分感谢了。老师让用t
我们c语言结课,做结课设计。做汉诺塔。网上找了个程序,改了一下,就差在任意情况下按esc退出不会弄了。麻烦高手帮我在我的程序上改一个esc退出,谢谢~~~~是在我的程序上改,不是网上找个那个while的死循环程序复制上来,改好了100分一定会给的,帮个忙,十分感谢了。老师让用tc2.0,不让用vc6.0.。。。。#include #include #include #include /* --------------------------------------------------------------------------------------- */#define PATH "e:\\TC\\BGIOBJ"#define N 100/* --------------------------------------------------------------------------------------- */int x[N][2], y[N][2] ,s;int countA, countB, countC ;/* --------------------------------------------------------------------------------------- */void init(int numT) ;void HanoiAuto(char from,char to,char aux,int n);void Hanoi(char from, char to, char aux, int n) ;void movTower(int n, char from, char to) ;void movup(int arrayE, int x1, int x2) ;void movdown(int arrayE, int x1, int x2, int countN) ;void movright(int arrayE, int x, int n) ;void movleft(int arrayE, int x, int n) ;/* --------------------------------------------------------------------------------------- */void main(){int gdriver=DETECT, gmode,n,a ;initgraph(&gdriver, &gmode, PATH) ;printf("choose the speed,100 or 200 or 300 or 400\n");scanf("%d",&s);printf("enter the number of dish\n");scanf("%d",&n);countA=n ;countB=0 ;countC=0 ;printf("1.handly\ to\n");scanf("%d",&a);clearviewport();init(n);getch();if(a==1)Hanoi('A', 'C', 'B', n) ;elseHanoiAuto('A','C','B',n);getch() ;closegraph() ;}/* --------------------------------------------------------------------------------------- */void init(int numT){int i ;int count=0 ;bar(10, 70, 629, 409) ;/* the border */setfillstyle(1, 0) ;bar(30, 359, 609, 369) ;/*the di */bar(121, 150, 131, 358) ;/*the lef */bar(314, 150, 324, 358) ;/*the mid */bar(507, 150, 517, 358) ;/*the rig */setcolor(8) ;for(i=numT-1 ; i>=0 ; i--) /*pan zi*/{ x[count][0]=121-(numT-i)*4 ; x[count][1]=131+(numT-i)*4 ; y[count][0]=348-i*11 ; y[count][1]=358-i*11 ; rectangle(x[count][0], y[count][0], x[count][1], y[count][1] ) ; count++ ;}}/* --------------------------------------------------------------------------------------- */void HanoiAuto(char from,char to,char aux,int n){if(n==1)movTower(1,from,to);else { HanoiAuto(from,aux,to,n-1); movTower(n,from,to); HanoiAuto(aux,to,from,n-1); }}/* --------------------------------------------------------------------------------------- */void Hanoi(char from, char to, char aux, int n){if(n==1) { getch(); movTower(1, from, to) ; }else{ Hanoi(from, aux, to, n-1) ; getch(); movTower(n, from, to) ; Hanoi(aux, to, from, n-1) ;}}/* --------------------------------------------------------------------------------------- */void movTower(int n, char from, char to){int arrayE ;arrayE=n-1 ;moverel(30,400);if(from=='A' &&
展开
全部