728x90
#include "stdio.h"
#include "stdlib.h"
int h=0;
void move(int from, int to)
{
printf("│ [%d]에서 [%d]으로 옮김 │\n", from, to);
h++;
}
void hanoi(int n, int from, int by, int to)
{
if(n==1)
{
move(from,to);
}
else
{
hanoi(n-1,from,to,by);
move(from,to);
hanoi(n-1,by,from,to);
}
}
void main(int n)
{
printf("탑이 몇층으로 이루어져 있습니까?\n▷ ");
scanf("%d", &n);
system("cls");
printf("\n\n┌────────────┐\n");
hanoi(n,1,2,3);
printf("│────────────│");
if(h<10)
{
printf("\n│ %d회 옮겼습니다. │\n", h);
}
else if(h<100)
{
printf("\n│ %d회 옮겼습니다. │\n", h);
}
else if(h<1000)
{
printf("\n│ %d회 옮겼습니다. │\n", h);
}
else
{
printf("\n│ %d회 옮겼습니다. │\n", h);
}
printf("└────────────┘\n\n");
}
'it > programming' 카테고리의 다른 글
| 네이트온 가젯이 있다면 좋겠다. (2) | 2012.02.29 |
|---|---|
| java UDP 채팅방 서버, 클라이언트 제작 (0) | 2012.02.29 |
| java 메모장 소스 (0) | 2012.02.29 |