seergiomv

Ordenar un array aleatorio

Dec 30th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define N 500
  4. void array();
  5. int main(){
  6.     int a[N];
  7.     array(a);
  8. }
  9. void array(int a[N]){
  10.     int cero = 0;
  11.     for (int i = 0; i < N; i++){
  12.         a[i] = rand() % 2001;
  13.     }
  14.     for (int i = 1; i < N; i++){
  15.         for (int j = 0; j < N -1; j++){
  16.             if (a[j] > a[j+1]){
  17.                 cero = a[j];
  18.                 a[j] = a[j+1];
  19.                 a[j+1] = cero;
  20.             }
  21.         }
  22.     }
  23.     for (int i = 0; i < N; i++){
  24.         printf("%d\n",a[i]);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment