Odd and square numbers: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task}} ;Task: <br> Find odd and square numbers under '''1.000''' =={{header|Python}}== <lang python> szamok=[] i=1 limit = 1000 for i in range(limit): num = i*i...")
 
No edit summary
Line 21: Line 21:
<pre>
<pre>
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]
</pre>

=={{header|Ring}}==
<lang ring>
see "working..." + nl
limit = 1000
list = []

for n = 1 to limit
for m = 1 to limit
if (n%2 = 1) and (n = pow(m,2))
add(list,n)
ok
next
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>
{{out}}
<pre>
working...
[1,9,25,49,81,121,169,225,289,361,441,529,625,729,841,961]
done...
</pre>
</pre>

Revision as of 12:54, 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 under 1.000

Python

<lang python> szamok=[] i=1 limit = 1000

for i in range(limit):

   num = i*i
   if (num < 1000 and num > 99 and (num % 2 == 1)):
       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 n = 1 to limit

   for m = 1 to limit
       if (n%2 = 1) and (n = pow(m,2))  
           add(list,n)
       ok
   next

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...
[1,9,25,49,81,121,169,225,289,361,441,529,625,729,841,961]
done...