Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

하노이탑/한유선김민경

From ZeroWiki
Revision as of 05:31, 7 February 2021 by imported>Unknown
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
#include<stdio.h>

int cnt = 0;
void movehanoi(char a, char b, char c, int n);

void movehanoi(char from, char temp, char to, int n)
{
  if(n==1){
        ++cnt;
        printf("%5d:말뚝 %c 에서 말뚝 %c 로 원반 %d 을 이동 \n", cnt, from, to, 1);
}
  else{
        movehanoi(from, to, temp, n-1);
        ++cnt;
        printf("%5d:말뚝 %c 에서 말뚝 %c 로 원반 %d 을 이동 \n", cnt, from, to, n);
        movehanoi(temp, from, to, n-1);
}

}




//함수시작
int main(void)
{
       int n;

       printf("하노이 탑에서 옮기려는 원반의 수는?>");
       scanf("%d", &n);

       movehanoi('A', 'B', 'C', n);

       return 0;
}
//함수종료

하노이탑