-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path005_loops.rb
More file actions
executable file
·64 lines (49 loc) · 931 Bytes
/
005_loops.rb
File metadata and controls
executable file
·64 lines (49 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
a1 = []
lim = 1000
show = 5
if a1.empty?
i = 0
while i<=lim
a1[i] = (rand*lim).to_int
i += 1
end
end
#Show Elmnts
puts "\nRandom:"
0.upto(show){ |i| print a1[i],"\t"}
print ". . .\t"
(lim-show).upto(lim){ |i| print a1[i],"\t"}
puts
#Array Sort
unless a1.empty?
for i in 0..lim
for j in 0..lim
a1[i] , a1[j] = a1[j] , a1[i] if a1[i]<=a1[j]
end
end
end
puts "\nSort:"
0.upto(show){ |i| print a1[i],"\t"}
print ". . .\t"
(lim-show).upto(lim){ |i| print a1[i],"\t"}
puts
#==========================================================================================
puts "\n\n"
matrix_num = 10
a2 = []
#matrix
for i in 0..(matrix_num)
a2[i] = Array.new
end
for i in 0..matrix_num
for j in 0..matrix_num
a2[i][j] = i+j
end
end
matrix_num.times{ |i|
print "["
matrix_num.times{ |j|
print "\t",a2[i][j]
}
puts "\t]"
}