무한루프에서 벗어나질 않아요..
한빛
질문 제목 : 잘못된 곳 지적무한루프에서 빠져나오질 않아요.질문 내용 :
#include stdio.h
#include stdlib.h
#include time.h
#include windows.h
void gotoxy(int x, int y);
int check(int a[3][3], int b[3][3])
{
int i, j;
for (i = 0; i 3; i++) {
for (j = 0; j 3; j++) {
if (a[i][j] != a[i][j]) return 0;
}
}
return 1;
}
int main()
{
int a,b,c,d;
int map[3][3];
int first[3][3];
int count;
srand((unsigned)time(null));
for(a=0;a3;a++){
for(b=0;b3;b++)
{
map[a][b]=rand()%2;
}
}
for(c=0;c3;c++){
for(d=0;d3;d++)
{
first[c][d]=rand()%2;
}
}
for(a=0;a3;a++){
for(b=0;b3;b++)
{
if(map[a][b]==1)printf(■);
else if(map[a][b]==0)printf(□);
}
printf(\n);
}
count=0;
while(check(first, map) != 0)
{
gotoxy(1,5);
for(c=0;c3;c++){
for(d=0;d3;d++)
{
if(first[c][d]==1)printf(■);
else if(first[c][d]==0)printf(□);
}
printf(\n);
}
for(c=0;c3;c++){
for(d=0;d3;d++)
{
first[c][d]=rand()%2;
}
}
count++;
}printf(%d회만에 출력!\n, count);
return 0;
}
void gotoxy(int x, int y)
{
coord pos = {x-1, y-1};
setconsolecursorposition(getstdhandle(std_output_handle), pos);
}
임시 배열에 저장하는 것이 아닌 따로 배열을 만들고 그것을 계속 변화시키면서 첫번째배열과 같게 만들어주는데 그게 몇십분이 지나도록 무한 루프에서 빠져나오질않네요.
무엇이 잘못된걸까요, 이제 고지가 코 앞인데….