Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class Exercicio3
- {
- public static void Main()
- {
- int n = 61;
- char[] celula = new char[n];
- for (int i = 0; i < n; i++)
- celula[i] = ' ';
- /* 8 = celúla preta, espaço = célula branca */
- celula[30] = '8';
- char[] novaCelula = new char[n];
- for (int i = 0; i < n; i++)
- novaCelula[i] = ' ';
- int contador = 0;
- /* repete 30 vezes o procedimento */
- while (contador < 30) {
- for (int i = 1; i < n - 1; i++) {
- /* verifica as regras */
- if (celula[i] == ' ' && celula[i - 1] == ' ' && celula[i + 1] == ' ')
- novaCelula[i] = ' ';
- else if (celula[i] == '8' && celula[i - 1] == '8' && celula[i + 1] == ' ')
- novaCelula[i] = ' ';
- else
- novaCelula[i] = '8';
- }
- /* imprime o resultado atual */
- Console.WriteLine(new string(novaCelula));
- /* copia o novo array para o inicial */
- novaCelula.CopyTo(celula, 0);
- contador++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement