Skip to content

Instantly share code, notes, and snippets.

@gollilla
Created May 24, 2018 00:48
Show Gist options
  • Save gollilla/964d7d894e4bc4cf99eda188bd0e1501 to your computer and use it in GitHub Desktop.
Save gollilla/964d7d894e4bc4cf99eda188bd0e1501 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void){
srand(time(NULL));
int data[20];
int i,j,tmp;
printf("[");
for(i=0;i<20;i++){
data[i] = rand() % 100 + 1;
printf("%d,", data[i]);
}
printf("]\n\n");
for(i=2;i<20;i++){
for(j=i;j>0;j--){
if(data[j]<data[j-1]){
tmp = data[j-1];
data[j-1] = data[j];
data[j] = tmp;
}
}
}
printf("[");
for(i=0;i<20;i++){
printf("%d,", data[i]);
}
printf("]\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment