C语言读取矩阵我有25个数以空格隔开 例如 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5.怎么读入 一个 a[5][5]的矩阵.或者有人能直接做出以下题目的.Problem 4Write a program zombie.c that prompts the user for a 5 \2 5 array

来源:学生作业学帮网 编辑:学帮网 时间:2024/05/14 07:56:12

C语言读取矩阵
我有25个数以空格隔开 例如 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5.怎么读入 一个 a[5][5]的矩阵.
或者有人能直接做出以下题目的.
Problem 4
Write a program zombie.c that prompts the user for a 5 \2 5 array of zeros and ones (entered
consecutively row by row) and run the following game for three times:
\x0f Each element of the array is either a zombie (if it is 0) or a human (if it is 1).
\x0f The neighbors of each elements are those horizontally,vertically,or diagonally adjacent to
it,hence corner elements have three neighbors,elements on the side have \x0cve neighbors,and
elements in the middle have eight neighbors.
\x0f At each iteration of the game the following events occur:
{ Any human with less than two (namely 0 or 1) human neighbors is attacked by the
zombies and becomes a zombie.
{ Any zombie with more than two (namely 3 up to 8) human neighbors is cured by the
humans and becomes a human.
Denoting zombies by - and humans by \3,the program prints the initial state of the game (provided
by the user),and then runs the above iterations three times,printing the new state each time.

int main()
{
int a[5][5];
int i,j;
for(i=0;i