Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- // Numeros aleatorios ate um limite considerado
- // Autor: Alexandre Campos
- int main()
- {
- // Declaracao
- int aleatorio;
- int n = 15; // Quantidade de numeros a serem gerados
- int limite = 20; // Aleatorios de 0 ate 19
- // Informa uma fonte para os numeros aleatorios
- // time(NULL) informa os segundos desde 01/01/1970 ate agora
- srand(time(NULL));
- // Repetir n vezes
- for (int i=0; i<n; i++)
- {
- // Gera um numero aleatorio, randomico (random)
- aleatorio = rand() % limite; // De 0 ate 19, que e 20-1.
- // Exibicao em tela
- printf("Numero aleatorio e %d\n", aleatorio);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment