I'm having problems setting up the grid for this problem and i'm not really sure if it's completely correct..So could you please help me out where you can..

Here's the question:

WRITE A PROGAM TO STIMULATE THE “GAME OF LIFE”. THERE IS A CITY THAT IS LAID OUT AS A GRID. EACH CELL IN THE GRID CAN BE EITHER ALIVE OR DEAD. EACHCELL HAS A MAXIMUM OF EIGHT NEIGHBOURS, WHICH ARE THE CELLS ADJACENT TO IT IN THE GRID. IF A CELL HAS MORE THAN FOUR NEIGHBOURS, IT WILL DIE OF OVERCROWDING IN THE GENERATION. IF IT HAS LESS THAN THREE NEIGHBOURS IT WILL ALSO DIE IN THE NEXT GENERATION FROM LONELINESS, OTHERWISE THE CELL LIVES IN THE NEXT GENERATION. THE GRID HAS NO BOUNDARIES, SO IF YOU ARE AT THE LAST CELL OF THE RIGHT EDGE OF THE GRID AND MOVE ONE CELL TO THE RIGHT, YOU WILL BE IN THE FIRST OF THE LEFT EDGE OF THE GRID AND VICE VERSA. IF YOU ARE THE LAST CELL AT THE BOTTOM OF THE GRID AND MOVE DOWN ONE CELL, YOU WILL BE AT THE FIRST CELL AT THE TOP OF THE GRID AND VICE VERSA. THE PROGRAM SHOULD RANDOMLY POPULATE A 50*50 GRID WITH LIVING CELLS, DISPLAY THE GRID ON THE SCREEN AND SHOULD ITERATE THROUGH 1000 GENERATIONS. AFTER EACH GENERATION THE NEW GRID IS DISPLAYED ON THE SCREEN.

And here's the code:

Code:#include <stdio.h> #include <stdlib.h> #include <windows.h> int array[50][50]={0}; int array1[50][50]={0}; int function1(int num,int num2) { int num3; num3=array[num][num2]; return num3; } int function2(int num,int num2) { int num3=0; if(num<0&&num2<0) { num3=function1(49,49); return num3; } else if(num<0&&num2>49) { num3=function1(49,0); return num3; } else if(num>49&&num2<0) { num3=function1(0,49); return num3; } else if(num>49&&num2>49) { num3=function1(0,0); return num3; } else if(num<0&&num2>=0) { num3=function1(49,num2); return num3; } else if(num>49&&num2>=0) { num3=function1(0,num2); return num3; } else if(num>=0&&num2<0) { num3=function1(num,49); return num3; } else if(num>=0&&num2>49) { num3=function1(num,0); return num3; } return 0; } void function3() { int num,num2; for(num=0;num<50;num++) { for(num2=0;num2<50;num2++) { array[num][num2]=array1[num][num2]; } } for(num=0;num<50;num++) { for(num2=0;num2<50;num2++) { array1[num][num2]=0; } } } int function4(int num,int num2) { int num3=0; if((num<0||num>49)||(num2<0||num2>49)) { num3=function2(num,num2); return num3; } else { num3=function1(num,num2); return num3; } } int function5(int num,int num2) { int num3=0; if((function4((num-1),(num2-1)))==1) { num3++; } if((function4((num-1),num2))==1) { num3++; } if((function4((num-1),(num2+1)))==1) { num3++; } if((function4(num,(num2+1)))==1) { num3++; } if((function4((num+1),(num2+1)))==1) { num3++; } if((function4((num+1),num2))==1) { num3++; } if((function4((num+1),(num2-1)))==1) { num3++; } if((function4(num,(num2-1)))==1) { num3++; } return num3; } void function7() { int num,num2; for(num=0;num<50;num++) { for(num2=0;num2<50;num2++) { if(((function5(num,num2))==4)||((function5(num,num2))==3)) { array1[num][num2]=1; } else { array1[num][num2]=0; } } } } void main() { int num,num2,num3; array[49][0]=1; array[49][49]=1; array[0][0]=1; array[0][1]=1; array[0][2]=1; array[0][3]=1; array[0][4]=1; array[0][5]=1; array[0][6]=1; array[0][7]=1; array[1][49]=1; array[1][49]=1; array[1][49]=1; array[1][49]=1; array[1][49]=1; array[1][49]=1; array[1][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; array[2][49]=1; for(num=0;num<50;num++) { for(num2=0;num2<50;num2++) { if((array[num][num2])==1) { printf("*"); } else { printf(" "); } }printf("\n"); } for(num3=0;num3<300;num3++) { system("cls"); function7(); function3(); for(num=0;num<50;num++) { for(num2=0;num2<50;num2++) { if((array[num][num2])==1) { printf("*"); } else { printf(" "); } }printf("\n"); }Sleep(240); } }