bool llenar(int m[10][10],int i,int j,int v[10][10]){...m[i][j]=rand() % 1000 + 1;v[i][j]=m[i][j];if(m[i][j]!=v[i][j]) //esto no puede darse nuncam[i][j]=rand() % 1000 + 1;...}
void mostrar(int m[10][10]){ cout<<"\n"; for (int i=0;i<10;i++){ for(int j=0;j<10;j++){ cout<<m[i][j]<<"\t"; } cout<<"\n"; } }
/*generar una matriz de 10x10 con númerosno repetidos entre 1 y 10000 indicandoel minimo hasta aqui he podido hacerlo, ademas de las funciones que coloque para que el programatenga un mejor aspecto */#include <iostream> #include <stdio.h>#include <stdlib.h>#include <time.h>#include <windows.h>#include <conio.h>int color(int);int main(){ //system("color 70"); srand(time(NULL));int n,matriz[10][10]={0}, i=rand()%10+1, j=0, x, y,minimo=10001,i_min=0,j_min=0;/*************** CALCULO ***********/do{ x=rand()%10;y=rand()%10;if(matriz[x][y]==0 ){ matriz[x][y]=i; if (i<minimo) { minimo=i; i_min=x; j_min=y; } i+=rand()%19; j++; }}while (j<100);/*************** IMPRESION CON COLOR ***********/for(i=0;i<10;i++){ putchar('\n');for(j=0;j<10;j++) { if (i==i_min && j==j_min) n=228; else n=113; color (n); printf(" %i ", matriz[i][j]); color (7); printf("\t"); } system("pause"); } color (96); printf("\n\nminimo = %d en la posicion ",minimo); color (228); printf(" (%d,%d) \n",i_min+1,j_min+1); color (7); return 0; } int color (int n){ SetConsoleTextAttribute(GetStdHandle (STD_OUTPUT_HANDLE), n ); getch();}
class tabla{ int tab[10][10]; public: tabla(); bool esta(int a); void mostrar(); ... }; tabla::tabla(){ int a,x=0,y=0; srand(time(NULL)); while (x<100){ while(y<100){ //no for porque for asigne o no asigne numero incrementa a=rand() %1000 +1; if (!esta(a)){ tab[x][y]=a; y++; } } x++; } } bool tabla::esta(int a){ int repe=0,x=0,y=0; while ((x<100)&&(repe!=1)){ while((y<100)&&(repe!=1)){ if (tab[x][y]==a) repe=1; y++; } x++; } return repe; //0=false 1=true }