Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h> // rand() ou random()
- #include <time.h>
- #define n 100
- // ordenando o vetor com o algoritmo bubblesort
- int main(void)
- {
- int i,a[n],j,temp;
- // gerando nova sequencia de numeros aleatórios:
- srand(time(0));
- for (i=0;i<n;i++)
- {
- a[i]=rand()%n +1;
- a[i]=(double) rand()/RAND_MAX*n;
- // printf("%d \n",a[i]);
- }
- for (i=0;i<n-1;i++) {
- for(j=n-1;j>i;j--) {
- if (a[j-1] > a[j])
- {
- temp=a[j-1];
- a[j-1]=a[j];
- a[j]=temp;
- }
- }
- }
- for (i=0;i<n;i++)
- printf("%d \n",a[i]);
- // RAND_MAX definido no <stdlib.h>
- // número aleatório entre 1 e RAND_MAX
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement