para poder hacer esa comprobación tienes que trabajar con float y tu estas trabajando con int ala hora de hacer la comprobacion te daria un error.
y tu programa que es lo que hace exactamente??
y tu programa que es lo que hace exactamente??
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
void leermatriz()
{
int matriz[50][50];
int fila, columna,i,j;
//estas variables solo serán tomadas en cuenta dentro de esta función
void imprimirmatriz()
{
int matriz[50][50];
int fila, columna,i,j;
//estas variables solo serán tomadas en cuenta dentro de esta función
//y serán distintas a las de la función anterior
//El juego de la vida
#include <stdio.h>
#include <windows.h>
#include <time.h>
int columnas;
void gotoxy(int x,int y);
void dibujarrejilla(int fil, int col);
void dibujarCelula(int rejilla[][columnas], int filas, int col);
void llenarRejilla(int rejilla[][columnas], int filas, int col);
void comprobacion(int rejilla[][columnas], int filas, int col);
int main(){
int i, j, filas, col;
do{
printf("Coloque el numero de filas\n");
scanf("%d", &filas);
if(filas<10 || filas>40) printf("intodusca un numero mayor que 9 o menor que 41\n");
}while(filas<10 || filas>40);
do{
printf("Coloque el numero de columnas\n");
scanf("%d", &col);
if(col<10 || col>29) printf("intodusca un numero mayor que 9 o menor que 30\n");
}while(col<10 || col>29);
columnas = col;
int rejilla[filas][col];
llenarRejilla(rejilla, filas, col);
dibujarrejilla(filas, col);
do{
dibujarCelula(rejilla, filas, col);
comprobacion(rejilla, filas, col);
Sleep(1000);
//getch();
}while(1);
getch();
return 0;
}
void gotoxy(int x,int y){
HANDLE hcon;
hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y= y;
SetConsoleCursorPosition(hcon,dwPos);
}
void llenarRejilla(int rejilla[][columnas], int filas, int col){
int i, j;
srand(time(NULL));
for(i=0; i<filas; i++){
for(j=0; j<col; j++){
rejilla[i][j]=rand()%2;
}
}
}
void dibujarrejilla(int fil, int col){
int i, j;
system("cls");
for(i=0; i<fil; i++){
for(j=0; j<col; j++){
if(i==0){
if(j==0){
gotoxy(i*2,j*2);
printf("%c%c",201,205);
}else{
if((col-1) == j){
gotoxy(i*2,j*2);
printf("%c%c",200,205);
gotoxy(i*2,(j*2-1));
printf("%c",186);
}else{
gotoxy(i*2,j*2);
printf("%c%c",204,205);
gotoxy(i*2,(j*2-1));
printf("%c",186);
}
}
}else{
if(j==0){
gotoxy(i*2,j*2);
printf("%c%c",203,205);
}else{
if((col-1) == j){
gotoxy(i*2,j*2);
printf("%c%c",202,205);
gotoxy(i*2,(j*2-1));
printf("%c",186);
}else{
gotoxy(i*2,j*2);
printf("%c%c",206,205);
gotoxy(i*2,(j*2-1));
printf("%c",186);
}
}
if((fil-1) == i){
if(j==0){
gotoxy(i*2,j*2);
printf("%c ",187);
}else if((col-1) == j){
gotoxy(i*2,j*2);
printf("%c ",188);
}else{
gotoxy(i*2,j*2);
printf("%c ",185);
}
}
}
}
}
}
void dibujarCelula(int pos[][columnas], int filas, int col){
int j, i;
for(i=0; i<filas-1; i++){
for(j=0; j<col-1; j++){
if(pos[i][j] == 1){
gotoxy((i*2)+1,(j*2)+1);
printf("%c", 219);
}else{
gotoxy((i*2)+1,(j*2)+1);
printf(" ");
}
}
}
}
void comprobacion(int rejilla[][columnas], int filas, int col){
int i, j, x, y, reja[filas][col], vivas;
for(i=0; i<filas-1; i++){
for(j=0; j<col-1; j++){
if(rejilla[i][j] == 0){
vivas = 0;
for(x=0; x<3; x++){
for(y=0; y<3; y++){
if((i+1)-x == -1 || (j+1)-y == -1 || (i+1)-x > filas-1 || (j+1)-y > col-1){
continue;
}else if((i+1)-x == i && (j+1)-y == j){
reja[i][j] = rejilla[i][j];
}else if(rejilla[(i+1)-x][(j+1)-y] == 1){
vivas++;
}
}
}
if( vivas == 3){
reja[i][j] = 1;
}
}else if(rejilla[i][j] == 1){
vivas = 0;
for(x=0; x<3; x++){
for(y=0; y<3; y++){
if((i+1)-x == -1 || (j+1)-y == -1 || (i+1)-x > filas-1 || (j+1)-y > col-1){
continue;
}else if((i+1)-x == i && (j+1)-y == j){
reja[i][j] = rejilla[i][j];
}else if(rejilla[(i+1)-x][(j+1)-y] == 1){
vivas++;
}
}
}
if(vivas == 2 || vivas == 3){
reja[i][j] = 1;
}else{
reja[i][j] = 0;
}
}
}
}
for(i=0; i<filas; i++){
for(j=0; j<col; j++){
rejilla[i][j] = reja[i][j];
}
}
}