SOLUTION: Write a program to print the following series 2 5 11 17 23 31 41 47 59 ...

Algebra.Com
Question 1062750: Write a program to print the following series
2 5 11 17 23 31 41 47 59 ...

Found 2 solutions by rothauserc, Edwin McCravy:
Answer by rothauserc(4718)   (Show Source): You can put this solution on YOUR website!
This is a list of every second prime beginning with 2.
:
The index into the list of primes would be (2n-1) where n = 1, 2, ......k
:
You would have to set k to some integer, for example 100
:
There are plenty of examples of c or java code on the internet to generate prime numbers, store them in a matrix and then use the index (2n-1) into the matrix to print out the every second prime number list
:

Answer by Edwin McCravy(20056)   (Show Source): You can put this solution on YOUR website!
The sequence is the 1st prime, the 3rd prime, the 5th prime, etc., i.e.
every other prime.

The only language I know is LibertyBasic. Here is the program in that
language. The ' indicates a comment line.
--------------------------------------------------------------------------

           'We begin by printing the first term. The only term that's even.
           'and setting the prime count = 1

print 2;" ";
count = 1

          'Now we need try only odd numbers n from 5 to 100. That's why the
          'step 2" in the next executable line. If we want numbers higher
          'than 100, then we change the 100 to a higher number.

for n = 3 to 100 step 2

pr = 1   
          'We test each n to see if it is prime. We use 1 or 0
          'values of "pr" to indicate whether n is prime or not
          'if pr=1 it is prime, and if pr=0 it is not prime
          'We started above by setting pr=1, for we change pr to 0
          'if n is not prime. Since n is odd, we only
          'need to see if n is divisible by odd numbers,
          'which is why the "step 2" in the next line.

for k = 3 to n-1 step 2

          'the next line makes pr=0 if n is divisible by k

if n mod k = 0 then pr=0

next k

          'if n is not prime the next line skips to 1 for the next n value

if pr = 0 then 1

          'if n is prime, we increase the prime count by 1

count = count+1

          'the next line determines whether the count is even or
          'odd.  If it's odd, we print n; if even we skip to 1

if count mod 2 = 0 then 1 

print n;" ";

1 next n

print "..."

-----------------------------------------

Edwin

RELATED QUESTIONS

write a c progaram to print the following series 2 5 11 17 23 31 41 47 59 (answered by solver91311)
2 5 11 17 23 31 41 47 59 how this series is... (answered by Edwin McCravy)
We have a sequence: 11, 17, 2, 29, 31, 41, 47, ... What is the eighth number? And... (answered by ikleyn)
what is the sequence of this (2, 3, 4, 5, 7, 8 ,9, 10, 11, 13, 14, 15, 16 ,17, 19, 21,... (answered by richard1234)
A prime number is a number that is evenly divided only by 1 and itself. The prime numbers (answered by ikleyn)
What number comes next? Please help :) Thank you! 3, 5, 11, 17, 31, 41, 59, 67,... (answered by addingup)
The Prime numbers between successive gaps of ten numbers are: 2, 3, 5, and 7. 11,... (answered by rapaljer)
Subject: locating a number in a triangular array of numbers [Question] if the... (answered by scott8148)
41, 31, 23, 17, 11,______ what would be the next term? Thanks,... (answered by solver91311)