Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: ANTÓN RAMIREZ en 14 Diciembre 2010, 21:22 pm



Título: Numeros aleatorios en C
Publicado por: ANTÓN RAMIREZ en 14 Diciembre 2010, 21:22 pm
Aqui les dejo un programa de generacion de numeros aleatorios y cuya salida me devuelve el mayor de los aleatorios , espero que lo sepan usar , haber si por alli alguien me puede facilitar programas resueltos en C++

ATTE : ANTON RAMIREZ , LEONARDO VLADIMIR  (ALUMNO UNI)

Código:
//MACROS
#define randomize (srand(time(0)))
//Retorna un numero aleatorio [0, num-1]
#define random(num) (rand()%(num))
#define TOPE 1000
#define MAX(x,y) ((x)>(y)?(x):(y))

using namespace std;

int main()
{
   int i, n, mx, y;
   randomize;
   mx=random(TOPE);
   printf("Ingrese la cantidad de numeros a mostrar :");
   scanf("%d", &n);
   for(i=0;i<n;){
      y=random(TOPE);
      mx=MAX(mx, y);
      printf("%3d ", y);
      i=i+1;
   }
   printf("\n\nMayor NUMERO : %d ", mx);
   printf("\n\n");
   system("pause");
   return(0);
}
[/color][/font]