FranciscoSoccol

Lista 08 - Exercicio 12

Aug 10th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.88 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. //prototipo
  5. int* sorteiaNumeros(int qtdeNum, int limInf, int limSup);
  6. //global
  7. int *vet;
  8. //funçao main
  9. int main()
  10. {
  11.     int qtdeNum, limInf, limSup, i;
  12.     printf("Quantidade de numeros: ");
  13.     scanf("%d",&qtdeNum);
  14.     printf("Limite inferior e Limite superior s sorteio: ");
  15.     scanf("%d %d",&limInf,&limSup);
  16.     int *vet2;//vetor auxiliar
  17.     vet2=sorteiaNumeros(qtdeNum,limInf,limSup);//vetor auxiliar recebe vet
  18.     for(i=0;i<qtdeNum;i++,vet2++)
  19.         printf("%d ",*vet2);//exibe o vetor
  20.     return 0;
  21. }
  22. //funçao que sorteia
  23. int* sorteiaNumeros(int qtdeNum, int limInf, int limSup)
  24. {
  25.     int i;
  26.     vet=(int*)malloc(sizeof(int)*qtdeNum);
  27.     srand(time(NULL));//inicialando sortei
  28.     for(i=0;i<qtdeNum;i++)
  29.         vet[i]=(rand()%(limSup-limInf)+limInf);//sorteando os numeros e salvando em cada posiçao
  30.     return vet;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment