-
-
Save svracak/1908544 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
### a) Ispišite sve brojeve od 1 do 1000 koji su djeljivi sa 13 ili 7 | |
(1..1000).each do |x| | |
if x%13==0 and x%7==0 | |
print x | |
puts " ima ostatka" | |
end | |
end | |
### b) Napravite novi rječnik koji će sadržavati dva ključa. | |
### Ključevi: 15, 7 | |
### | |
### Pod ključem "15" u ovom hashu moraju biti svi brojevi | |
### od 1 do 1000 djeljivi sa 15 | |
### Pod ključem "7" u ovom hashu moraju biti svi brojevi | |
### od 1 do 1000 djeljivi sa 7 | |
b = {7 => " ", 15 => " "} | |
(1..1000).each do |x| | |
if x%7==0 | |
b[7] << "#{x} " | |
end | |
if x%15==0 | |
b[15] << "#{x} " | |
end | |
end | |
### c) Ispišite koliko postoji vrijendosti za svaki ključ iz prethodnog zadatka | |
print "Elemenata pod kljucem 7 ima " | |
puts b[7].length | |
print "Elemenata pod kljucem 15 ima " | |
puts b[15].length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment