Jump to content

Primes whose sum of digits is 25

From Rosetta Code
Revision as of 02:15, 21 March 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task: Show primes which sum of digits is '''25''' <br> Let '''0 < n < 5000''' =={{header|Ring}}== <lang ring> load "stdlib.ring" row = 0 limit1 = 25 limit2...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Primes whose sum of digits is 25 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

Show primes which sum of digits is 25
Let 0 < n < 5000

Ring

<lang ring> load "stdlib.ring"

row = 0 limit1 = 25 limit2 = 5000

for n = 1 to limit2

   if isprime(n)
      bool = sum25(n)
      if bool = 1
         row = row + 1
         see "" + n + " "
         if (row%5) = 0
             see nl
         ok
      ok
   ok

next

func sum25(n)

    sum = 0
    str = string(n)
    for n = 1 to len(str)
        sum = sum + number(str[n])
    next
    if sum = limit1
       return 1
    ok

</lang>

Output:
997 1699 1789 1879 1987 
2689 2797 2887 3499 3697 
3769 3877 3967 4597 4759 
4957 4993 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.