소용돌이
#include <stdio.h>
#include <windows.h>
#include <time.h>
int x,y;
int t = 100;
void gotoxy(int x, int y);
void delay(clock_t n);
void left();
void right();
void up();
void down();
void main(){
int i,j;
x = 15;
y = 15;
gotoxy(x,y);
printf("A");
delay(1000);
for(i=1; i<=30; i++){
j = i;
if(j%2 == 1){
while(j--){
left();
}
j = i;
while(j--){
up();
}
}
if(j%2 == 0){
while(j--){
right();
}
j = i;
while(j--){
down();
}
}
}
gotoxy(30,30);
}
void left(){
x = x - 1;
gotoxy(x,y);
printf("A");
delay(t);
}
void up(){
y = y - 1;
gotoxy(x,y);
printf("A");
delay(t);
}
void right(){
x = x + 1;
gotoxy(x,y);
printf("A");
delay(t);
}
void down(){
y = y + 1;
gotoxy(x,y);
printf("A");
delay(t);
}
void delay(clock_t n){
clock_t start = clock();
while(clock() - start < n);
}
void gotoxy(int x, int y){
COORD Cur;
Cur.X=x;
Cur.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Cur);
}
'IT > Algorithm' 카테고리의 다른 글
Algorithm: 피보나치 수열(Fibonacci sequence) (0) | 2012.12.03 |
---|---|
Algorithm: 계승(Factorial) (0) | 2012.12.03 |
Algorithm: 큐(Queue) (0) | 2012.11.20 |
Algorithm: 이중 연결 리스트(Doubly linked list) (0) | 2012.11.13 |
Algorithm: 링크드리스트(Linked list) (0) | 2012.11.13 |