Summarize primes

From Rosetta Code
Revision as of 14:15, 15 April 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task: Summarize first n primes (p) and check if it primes, where '''p < 1000''' <br><br> =={{header|Ring}}== <lang ring> load "stdlib.ring" see "working..."...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Summarize primes 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

Summarize first n primes (p) and check if it primes, where p < 1000

Ring

<lang ring> load "stdlib.ring" see "working..." + nl see "Summarize primes:" + nl see "n sum" + nl row = 0 sum = 0 limit = 1000 Primes = []

for n = 2 to limit

   if isprime(n)
      add(Primes,n)
   ok

next

for n = 1 to len(Primes)

   sum = sum + Primes[n]
   if isprime(sum)
      row = row + 1
      see "" + n + " " + sum + nl
   ok

next

see "Found " + row + " numbers" + nl see "done..." + nl </lang>

Output:
working...
Summarize primes:
n sum
1 2
2 5
4 17
6 41
12 197
14 281
60 7699
64 8893
96 22039
100 24133
102 25237
108 28697
114 32353
122 37561
124 38921
130 43201
132 44683
146 55837
152 61027
158 66463
162 70241
Found 21 numbers
done...