C
1#include <stdio.h>
2#include <stdlib.h>
3
4int main(void)
5{
6 int i, j, t = 0;
7 int a[100];
8 int l = sizeof(a) / sizeof(int);
9
10 for(i = 0;i < 100; i++){
11 a[i] = rand()%101;
12 }
13
14 for(i = 0; i < l; i++){
15 for(j = 1; j < l; j++){
16 if(a[j] > a[j + 1]){
17 t = a[j + 1];
18 a[j + 1] = a[j];
19 a[j] = t;
20 }
21 }
22 }
23
24 for(i = 0;i < 100; i++){
25 printf("%d\n", a[i]);
26 }
27
28 return 0;
29}
0
2
3
5
8
11
11
12
13
13
15
17
18
18
19
22
23
23
24
24
24
24
25
25
29
31
32
33
33
33
35
35
37
38
39
39
39
41
45
46
48
49
49
51
51
51
52
52
54
57
57
58
59
60
60
61
62
63
63
64
65
66
67
67
68
69
70
71
71
71
71
71
72
74
74
75
76
77
78
80
80
83
83
83
85
86
87
90
92
94
94
94
95
95
96
97
99
99
99
99
見よう見まねでやってみました。
Ruby
1# encoding: utf-8
2
3a = Array.new(100).map { rand(100) }
4
5a.size.times do
6 (a.size - 1).times do |x|
7 a[x], a[x + 1] = a[x + 1], a[x] if a[x] > a[x + 1]
8 end
9end
10
11p a
12
13
Rubyバージョン
C#
1using System;
2
3namespace sort
4{
5 class Program
6 {
7 static void Main(string[] args)
8 {
9 int[] a = new int[100];
10
11 int seed = Environment.TickCount;
12
13 for(int i = 0; i < 100; i++)
14 {
15 Random rand = new Random(seed++);
16 a[i] = rand.Next(100);
17 }
18
19 for(int i = 0; i < a.Length; i++)
20 {
21 for(int j = 0; j < a.Length - 1; j++)
22 {
23 if(a[j] > a[j + 1])
24 {
25 int t = a[j + 1];
26 a[j + 1] = a[j];
27 a[j] = t;
28 }
29 }
30 }
31
32 foreach(int i in a) Console.WriteLine(i);
33 }
34 }
35}
36
C# バージョン。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。