#include<stdio.h>
void hannio(int n,char a,char b,char c);
int main()
{
unsigned long int n;
while((scanf("%d",&n))!=NULL)
{
hannio(n,'a','b','c');
printf("\n");
}
}
void hannio(int n,char a,char b,char c)
{
if(n==1)
printf("%c-->%c\n",a,c);
else
{
hannio(n-1,a,c,b);
printf("%c-->%c\n",a,c);
hannio(n-1,b,a,c);
}
}
scanf在读取不成功的时候返回值是EOF(-1)而不是NULL(0),因此NULL要换成EOF或-1
谢谢