Code:
#include <stdio.h>
typedef int mat[10][10];
void input(mat matr)
{
int x,y;
scanf("%d %d",&x,&y);
while(x!=-1&&y!=-1)
{
matr[x][y]==1;
scanf("%d %d",&x,&y);
}
}
void print(mat matr)
{
int i,j;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
printf("%d",matr[i][j]);
}
void zer(mat matr)
{
int i,j;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
if(!matr[i][j])
matr[i][j]=0;
}
void killcell(mat matr)
{
int countneib=0;
int i,j;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
if(matr[i][j]==1)
{
if(matr[i-1][j]==1)
countneib++;
if(matr[i+1][j]==1)
countneib++;
if(matr[i][j+1]==1)
countneib++;
if(matr[i][j-1]==1)
countneib++;
if(matr[i+1][j+1]==1)
countneib++;
if(matr[i+1][j-1]==1)
countneib++;
if(matr[i-1][j-1]==1)
countneib++;
if(matr[i-1][j+1]==1)
countneib++;
}
if(countneib>3)
matr[i][j]=0;
}
void createcell(mat matr)
{
int countneib=0;
int i,j;
for(i=0;i<10;i++)
for(j=0;j<10;j++)
if(matr[i][j]==0)
{
if(matr[i-1][j]==1)
countneib++;
if(matr[i+1][j]==1)
countneib++;
if(matr[i][j+1]==1)
countneib++;
if(matr[i][j-1]==1)
countneib++;
if(matr[i+1][j+1]==1)
countneib++;
if(matr[i+1][j-1]==1)
countneib++;
if(matr[i-1][j-1]==1)
countneib++;
if(matr[i-1][j+1]==1)
countneib++;
}
if(countneib==3)
matr[i][j]=1;
}
int main ()
{
char choice;
int i,j;
mat matr;
input(matr);
zer(matr);
print(matr);
scanf("%c",&choice);
while(choice!='n')
{
killcell(matr);
createcell(matr);
print(matr);
scanf("%c",&choice);
}
return 0;
}
The problem is that, there are weird numbers in the matrix.
Thanks