Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/01/2012, 12:57
Avatar de FelipePower
FelipePower
 
Fecha de Ingreso: diciembre-2011
Ubicación: Chile-Talca
Mensajes: 9
Antigüedad: 12 años, 4 meses
Puntos: 1
Información Respuesta: Problema con Matrices en C

Código C:
Ver original
  1. //IMPLEMENTACIÓN DE UN ALGORITMO GENÉTICO
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h> //incluye srand() y rand()
  5. #include <conio.h>
  6. #include <time.h> //incluye time()
  7.  
  8.  
  9. main()
  10. {
  11.     FILE *fin,*fout;
  12.    
  13.     int tm, tg, gen, g=0;
  14.     float pmut;
  15.     int i, j;
  16.     int mat[500][50], P_I;
  17.     int cont;
  18.  
  19.     srand(time(0));
  20.    
  21.     fin=fopen("ag.in","r");
  22.     fout=fopen("ag.out","w");
  23.  
  24.     if(fin==NULL){
  25.         printf("error");
  26.         exit(1);
  27.     }
  28.    
  29.     fscanf(fin, "%d", & tm);
  30.     fscanf(fin, "%d", & tg);
  31.     fscanf(fin, "%f", & pmut);
  32.     fscanf(fin, "%d", & gen);
  33.    
  34.     cont=0;
  35.  
  36.     for(i=0;i<tm;i++){
  37.         printf("Individuo %d: ", (i+1));
  38.         for (j=0;j<tg;j++){
  39.             mat[i][j]=rand()&1;
  40.             P_I=mat[i][j];  
  41.             printf("%d", P_I);
  42.            
  43.             if(mat[tm][tg]==1){
  44.                 cont++;
  45.             }  
  46.            
  47.            
  48.         }
  49.         printf("\n\n");
  50.     }
  51.        
  52.     printf("\n%d\n",cont);
  53.  
  54.     fprintf(fout, "Parámetros: %d %d %.1f %d\n", tm, tg, pmut, gen);
  55.    
  56.     fclose(fout);
  57. }





Pero no me funciona, me dice en el: printf("%d", cont) ... = 0 en todo, a que te refieres con agregar ese if.