Odd and square numbers: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3: | Line 3: | ||
;Task: |
;Task: |
||
<br> |
<br> |
||
Find odd and square numbers under '''1.000''' |
Find odd and square numbers (>99) under '''1.000''' |
||
=={{header|Python}}== |
=={{header|Python}}== |
Revision as of 13:50, 23 November 2021
Odd and square numbers is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
Find odd and square numbers (>99) under 1.000
Python
<lang python> iimport math szamok=[] limit = 1000
for i in range(1,int(math.ceil(math.sqrt(limit))),2):
num = i*i if (num < 1000 and num > 99):
szamok.append(num)
print(szamok) </lang>
- Output:
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]
Ring
<lang ring> see "working..." + nl limit = 1000 list = []
for i = 1 to ceil(sqrt(limit)) step 2
num = pow(i,2) if (num < 1000 and num > 99)
add(list,num)
ok
next
showArray(list)
see nl + "done..." + nl
func showArray(array)
txt = "" see "[" for n = 1 to len(array) txt = txt + array[n] + "," next txt = left(txt,len(txt)-1) txt = txt + "]" see txt
</lang>
- Output:
working... [121,169,225,289,361,441,529,625,729,841,961] done...
Wren
<lang ecmascript>import "./trait" for Stepped
System.print("Odd and square numbers under 1,000:") var squares = Stepped.new(1..1000.sqrt.floor, 2).map { |i| i * i }.toList System.print(squares)</lang>
- Output:
Odd and square numbers under 1,000: [1, 9, 25, 49, 81, 121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]