Gustavo-Augusto

lista 08 - exercicio 12

Aug 10th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int* soteiaNumeros(int qtdeNum, int limInf, int limSup);
  7.  
  8. int main ()
  9. {
  10.     int x,z,y,*q,i;
  11.     printf ("Informe a quantidade de numeros a serem sorteados: ");
  12.     scanf ("%d",&x);
  13.     printf ("\nInforme o limite inferior dos sorteios: ");
  14.     scanf ("%d",&y);
  15.     printf ("\nInforme o limite superior dos sorteios: ");
  16.     scanf ("%d",&z);
  17.     q = soteiaNumeros(x,y,z);
  18.     printf ("\n\n");
  19.     for(i=0;i<x;i++,q++)
  20.         printf ("%d ",*q);
  21.     return 0;
  22. }
  23.  
  24. int* soteiaNumeros(int qtdeNum, int limInf, int limSup)
  25. {
  26.     srand(time(NULL));
  27.     int i,*p;
  28.     int *vet = (int*)malloc(qtdeNum*sizeof(int));
  29.     p = vet;
  30.     for(i=0;i<qtdeNum;i++)
  31.     {
  32.         *p = rand()%(limSup-limInf+1) + limInf;
  33.         p++;
  34.     }
  35.     return vet;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment