Primes whose sum of digits is 25: Difference between revisions

Primes which sum of digits is 25 en FreeBASIC
(Primes which sum of digits is 25 en FreeBASIC)
Line 732:
Count: 17
</pre>
 
 
=={{header|FreeBASIC}}==
{{trans|AWK}}
<lang freebasic>
Function isprime(num As Ulongint) As Boolean
For i As Integer = 2 To Sqr(num)
If (num Mod i = 0) Then Return False
Next i
Return True
End Function
 
Function digit_sum(num As Integer) As Integer
Dim As Integer sum25 = 0
For j As Integer = 1 To Len(num)
sum25 += Val(Mid(Str(num),j,1))
Next j
Return sum25
End Function
 
Dim As Integer inicio = 1, final = 5000, total = 0
For i As Integer = inicio To final
If (isprime(i)) And (digit_sum(i) = 25) Then
total += 1
Print Using " ####"; i;
If (total Mod 9) = 0 Then Print
End If
Next i
Print !"\n\nSe encontraron"; total; " primos sum25 por debajo de"; finalSleep
</lang>
{{out}}
<pre>
997 1699 1789 1879 1987 2689 2797 2887 3499
3697 3769 3877 3967 4597 4759 4957 4993
 
Se encontraron 17 primos sum25 por debajo de 5000
</pre>
 
 
=={{header|Go}}==
2,130

edits