ramontricolor12

LISTA 08 - Exercício 12

Aug 12th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. /*CABEÇALHO
  2.     Arquivo: LISTA 08 - Exercício 12.c
  3.     Objetivo: Gerar uma lista de numeros aleatórios com especificações passadas pelo usuário, usando ponteiros.
  4.     Autor(a): Ramon Borges.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <time.h>
  10. //PROTOTIPO DE FUNÇÕES
  11. int* soteiaNumeros(int qtdeNum, int limInf, int limSup);
  12.  
  13. int main()
  14. {
  15.     int qtde, lim_inferior, lim_superior, *listaNum, i;
  16.  
  17.     printf("Informe a quantidade de termos do vetor, alem do limite\n inferior e superior dos numeros: ");
  18.     scanf("%d %d %d", &qtde, &lim_inferior, &lim_superior);
  19.     listaNum = soteiaNumeros(qtde, lim_inferior, lim_superior);
  20.     for(i = 0; i < qtde; i++, listaNum++)
  21.         printf("%d ", *listaNum);
  22.     free(listaNum);
  23.     return 0;
  24. }
  25.  
  26. int* soteiaNumeros(int qtdeNum, int limInf, int limSup)
  27. {
  28.     int *vetorNum, gerador, i;
  29.  
  30.     srand(time(NULL));
  31.     vetorNum = (int*) malloc(qtdeNum * sizeof(int));
  32.     for(i = 0; i < qtdeNum; i++)
  33.     {
  34.         gerador = (rand()%(limSup + 1 - limInf)) + limInf;
  35.         vetorNum[i] = gerador;
  36.     }
  37.     return vetorNum;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment