该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
// 1.cpp : Defines the entry point for the
console application.//
#include
#include
#include
#include
#include "stdafx.h"
int main(int argc, char* argv[])
{
int n,i=0,l=0;
int N;
int sum,k=1;
printf("Enter the size of the game:");
scanf("%d",&n)
printf("\n");
int **home;
home=(int**)malloc(n*sizeof(**home));
for(i=0;i
{
home[i]=(int*)malloc(n*sizeof(*home));
for(l=0;l
{
home[i][l]=0;
}
}
int **tmp;
tmp=(int**)malloc((n+2)*sizeof(**tmp));
for(i=0;i
{
tmp[i]=(int*)malloc((n+2)*sizeof(*tmp));
for(l=0;l
{
tmp[i][l]=0;
}
}
printf("Enter the time of the game:");
scanf("%d",&N);
printf("\n");
printf("Enter the start state:");
scanf("%d",&home[i][l]);
for(k=1;k
{
for(inti=1;i<=100;i++)
{
for(int l=1;l<=100;l++)
{
sum=home[i+1][l]+home[i+1][l-1]+home[i][l-1]+home[i-1][l-1]+home[i-1][l]+home[i-1][l+1]+home[i][l+1]+home[i+1][l+1];
switch(sum)
{
case 3:
tmp[i][l]=1;
break;
case 2:
tmp[i][l]=home[i][l];
break;
default:
tmp[i][l]=0;
break;
}
printf("%d",tmp[i][l]);
}
printf("\n");
}
memcpy(home,tmp,(n+2)*(n+2)*sizeof(**tmp));
printf("next\n");
}
free(home);
free(tmp);
return 0;
}
我是打算编一个生命游戏的程序,空间(二维数组)的大小由外界给,运行的时间由外界给。现在问题基本解决了,就是在调试的时候会出现问题,说该程序已停止工作。