Advertisement
campos20

Untitled

May 10th, 2020
1,044
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. // Numeros aleatorios ate um limite considerado
  6. // Autor: Alexandre Campos
  7.  
  8. int main()
  9. {
  10.     // Declaracao
  11.     int aleatorio;
  12.     int n = 15; // Quantidade de numeros a serem gerados
  13.     int limite = 20; // Aleatorios de 0 ate 19
  14.  
  15.     // Informa uma fonte para os numeros aleatorios
  16.     // time(NULL) informa os segundos desde 01/01/1970 ate agora
  17.     srand(time(NULL));
  18.  
  19.     // Repetir n vezes
  20.     for (int i=0; i<n; i++)
  21.     {
  22.         // Gera um numero aleatorio, randomico (random)
  23.         aleatorio = rand() % limite; // De 0 ate 19, que e 20-1.
  24.  
  25.         // Exibicao em tela
  26.         printf("Numero aleatorio e %d\n", aleatorio);
  27.     }
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement