Last active
July 24, 2018 08:07
-
-
Save gollilla/8642954c21201ba61d8f4754962d7497 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
int main(void){ | |
srand(time(NULL)); | |
int data[20]; | |
int i,j,tmp,min; | |
//ソート前のデータ表示 | |
printf("["); | |
for(i=0;i<20;i++){ | |
data[i] = rand() % 100 + 1; | |
printf("%d,", data[i]); | |
} | |
printf("]\n\n"); | |
//ソート | |
for(i=0;i<20;i++){ | |
min = i; | |
for(j=i;j<20;j++){ | |
if(data[j] < data[min]){ | |
min = j; | |
} | |
} | |
tmp = data[i]; | |
data[i] = data[min]; | |
data[min] = 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