Advertisement
horselurrver

Ch12 Ex5

Aug 15th, 2016
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #define NUM 10
  4. void intsrt(int array[], int num);
  5. int main(void){
  6.     int random[NUM];
  7.     int x;
  8.     for(x=0; x<NUM; x++){
  9.         random[x]=rand()%NUM+1;
  10.     }
  11.     printf("\n");
  12.     intsrt(random, NUM);
  13.     for(x=0; x<NUM; x++){
  14.         printf("%d\n", random[x]);
  15.     }
  16.     return 0;
  17. }
  18.  
  19. void intsrt(int array[], int num){
  20.     int temp;
  21.     int top, seek;
  22.    
  23.     for(top=0; top<num-1; top++){
  24.         for(seek=top+1; seek<num; seek++){
  25.             if(array[top]>array[seek]){
  26.                 temp=array[top];
  27.                 array[top]=array[seek];
  28.                 array[seek]=temp;
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement