Computer System Organizations Lab


refautomata
Answered Same DayApr 26, 2021

Answer To: refautomata

Ankita answered on Apr 29 2021
135 Votes
automata.c
#include
#include
int generation[5][5];
int countAlive(int i, in
t j) {
int alive = 0, m,n;
for(m=-1;m<2;m++) {
for(n=-1;n<2;n++) {
if(m+i<0 || m+i>=5 || n+j<0 || n+j>=5 || (m == 0 && n == 0))
continue;
else
if(generation[m+i][n+j] == 1)
alive++;
}
}
return alive;
}
void nextGeneration() {
int temp[5][5];
int i,j;
for(i=0;i<5;i++) {
for (j = 0; j <5; j++)
{
int alive = countAlive(i,j);
if(generation[i][j] == 1) {
if(alive == 2 || alive == 3)
temp[i][j] = 1;
else
temp[i][j] = 0;
} else {
if(alive == 3)
temp[i][j] = 1;
else
temp[i][j] = 0;
}
}
}
for(i=0;i<5;i++)
for...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here