Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define NUMBER 5
- void sort(int *input, int num) {
- int i, j, t;
- for (i = 1; i < num; i++) {
- t = input[i];
- if (input[i - 1] > t) {
- j = i;
- do { input[j] = input[j - 1]; j--; }
- while (j > 0 && input[j - 1] > t);
- input[j] = t;
- }
- }
- }
- int main(void) {
- int i, input[NUMBER];
- puts("整数配列を入力してください:");
- for (i = 0; i < NUMBER; i++) { printf("input[%d]:", i); scanf("%d", &input[i]); }
- sort(input, NUMBER);
- puts("昇順に並び替えた配列は:");
- for (i = 0; i < NUMBER; i++) printf("input[%d]:%d\n", i, input[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement