Show the (decimal) value of a number of 1s appended with a 3, then squared

From Rosetta Code
Revision as of 14:48, 5 April 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task: a(n) = (n 1's followed by a 3)^2, where '''0 <= n < 8''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring" decimals(0) see "working..." + nl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Show the (decimal) value of a number of 1s appended with a 3, then squared 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

a(n) = (n 1's followed by a 3)^2, where 0 <= n < 8

Ring

<lang ring> load "stdlib.ring"

decimals(0)

see "working..." + nl

row = 0 limit = 8

str = "3" for n = 1 to limit

   if n = 1
      strn = number(str) 
      res = pow(strn,2)
      see "{" + strn + "," + res + "}" + nl
   else
      str = "1" + strn
      strn = number(str) 
      res = pow(strn,2)
      see "{" + strn + "," + res + "}" + nl
   ok   

next

see "done..." + nl </lang>

Output:
working...
{3,9}
{13,169}
{113,12769}
{1113,1238769}
{11113,123498769}
{111113,12346098769}
{1111113,1234572098769}
{11111113,123456832098769}
done...