发新话题
打印

getchar()的用法

getchar()的用法

#include<stdio.h>
main()
{void hano();
int n;
printf("please input n:");
scanf("%d",&n);
hano(n,'a','b','c');
}
void hano(int n,char a,char b,char c)
  {if(n==1)
  printf("\n please move dise %d from %c to %c",n,a,c);
   else
  { hano(n-1,a,c,b);
   printf("\n please move dise %d from %c to %c",n,a,c);
   hano(n-1,b,a,c);
   }
   getchar();
  }
这是汉诺塔程序,WIN-TC环境下,用getchar()暂停程序观察结果。但是当输入为1以上时屏幕一闪而过,看不到结果。当输入为3以上时,要按回车多次才能显示全部输出结果。请问怎么解决?
相关主题

TOP

发新话题