Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- //prototipo
- int* sorteiaNumeros(int qtdeNum, int limInf, int limSup);
- //global
- int *vet;
- //funçao main
- int main()
- {
- int qtdeNum, limInf, limSup, i;
- printf("Quantidade de numeros: ");
- scanf("%d",&qtdeNum);
- printf("Limite inferior e Limite superior s sorteio: ");
- scanf("%d %d",&limInf,&limSup);
- int *vet2;//vetor auxiliar
- vet2=sorteiaNumeros(qtdeNum,limInf,limSup);//vetor auxiliar recebe vet
- for(i=0;i<qtdeNum;i++,vet2++)
- printf("%d ",*vet2);//exibe o vetor
- return 0;
- }
- //funçao que sorteia
- int* sorteiaNumeros(int qtdeNum, int limInf, int limSup)
- {
- int i;
- vet=(int*)malloc(sizeof(int)*qtdeNum);
- srand(time(NULL));//inicialando sortei
- for(i=0;i<qtdeNum;i++)
- vet[i]=(rand()%(limSup-limInf)+limInf);//sorteando os numeros e salvando em cada posiçao
- return vet;
- }
Advertisement
Add Comment
Please, Sign In to add comment