Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define MAXIMO 100
- // Gera numeros aleatorios
- // Autor Alexandre Campos
- // Gera 1 numero aleatorio
- int numero_aleatorio(){
- return random() % MAXIMO;
- }
- int * gera_numeros_aleatorios(int n){
- // Aloca n numeros inteiros na memoria
- int * resultado = malloc(n * sizeof(int));
- // Atribuicao de valores
- for (int i=0; i<n; i++){
- resultado[i] = numero_aleatorio();
- }
- return resultado;
- }
- int main()
- {
- // Chamar 1 vez
- srand(time(NULL));
- // Declaracao
- int n = 30;
- int * numeros_aleatorios;
- // Chamada da funcao que gera numeros aleatorios
- numeros_aleatorios = gera_numeros_aleatorios(n);
- // Exibir esses numeros
- for (int i=0; i<n; i++){
- printf("Posicao %d: %d\n", i, numeros_aleatorios[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement