matriz aleatoria

Iniciado por ALONSOQ, 18 Junio 2012, 17:56 PM

0 Miembros y 1 Visitante están viendo este tema.

ALONSOQ

Hola,

Con este código consigo generar una matriz aleatoria de n números, pero no soy capaz de conseguir que los números sean distintos

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>

int matriz [5];
int i, num;

main()
{
      for (i=0;i<5;i++)
      {
          srand (time(NULL));
          num= (rand()%16)+1;
          matriz=num;
         
          printf("%d\t",matriz);
         
          }
      getch();
      }


Podríais ayudarme por favor?

un saludo

STANHMAL


matriz[i]=num;
printf("%d\t",matriz[i]);


saca el srand del ciclo


srand(time(NULL));
for...


$4!u2
Power Metal vs Reggaeton



Que es mi ordenador mi tesoro que todo el mundo ha de temer. Mi ley, el ratón y el módem. Mi única patria, la red

0xDani

Usa las etiquetas de codigo y comprueba si el numero es igual al resto de subindices.

Saludos ;D
I keep searching for something that I never seem to find, but maybe I won't, because I left it all behind!

I code for $$$
Hago trabajos en C/C++
Contactar por PM

ALONSOQ

Cita de: STANHMAL en 18 Junio 2012, 18:29 PM

matriz[i]=num;
printf("%d\t",matriz[i]);


saca el srand del ciclo


srand(time(NULL));
for...


$4!u2

Muchas gracias;