Ver Mensaje Individual
  #2 (permalink)  
Antiguo 29/11/2013, 20:40
Avatar de vangodp
vangodp
 
Fecha de Ingreso: octubre-2013
Mensajes: 934
Antigüedad: 10 años, 7 meses
Puntos: 38
Respuesta: Error con un array en proyecto final

Esto es?
Código C++:
Ver original
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <ctime>
  4. #include <stdio.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. bool serepita(int num,int numero[][9]){
  10.     int b,c;
  11.     for (b=0;b<9;b++){
  12.         for(c=0;c<9;c++){
  13.             if (num==numero[b][c]){
  14.                 return true;
  15.             }
  16.             else{
  17.                 return false;
  18.             }
  19.         }
  20.     }
  21. }
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.     int s[9][9]={1,1,0,0,1,0,0,1,0,  1,1,0,0,0,0,0,0,1,  0,1,1,1,0,1,1,0,0,  0,0,0,1,1,0,1,0,1  ,0,1,0,0,1,0,0,1,0,  1,0,1,0,1,1,0,0,0, 0,0,1,1,0,1,1,1,0,  1,0,0,0,0,0,0,1,1,  0,1,0,0,1,0,0,1,1};
  26.     int az;
  27.     int x,y,
  28.         numero[9][9],
  29.         elnumero;
  30.     srand(time(NULL));
  31.     int i,j;
  32.  
  33.  
  34.     for (i=0; i<9; i++){
  35.         for(j=0; j<9; j++){
  36.             if(s[i][j]==1){
  37.                 az=1+rand()%(9);
  38.                 s[i][j]=az;
  39.             }
  40.  
  41.    
  42.         }  
  43.     }
  44.  
  45.     for (i=0;i<9;i++){
  46.         for(j=0;j<9;j++){
  47.             elnumero=numero[i][j];
  48.             while (serepita(elnumero,numero)){
  49.                 s[i][j]=rand()%9;
  50.             }
  51.         }
  52.     }
  53.  
  54.     for (i=0; i<9; i++){
  55.         for(j=0; j<9; j++){
  56.             if(s[i][j]==0)
  57.                 printf(" º   º ");
  58.             else
  59.                 printf( " º %d º ",s[i][j]);
  60.         }
  61.         cout<<"\n\n";    
  62.     }    
  63.  
  64.     system("PAUSE");
  65.     return EXIT_SUCCESS;
  66. }