Help!! Generating Prime Numbers
Author |
Message |
xSonu
|
Posted: Mon Jan 18, 2010 7:49 pm Post subject: Help!! Generating Prime Numbers |
|
|
What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
What is the problem you are having?
I can't figure out how to generate a list of of prime numbers. When the user is to suppose to enter the number up to which the program is to search for primes.
Describe what you have tried to solve this problem
To try to solve this problem. I have tried to user an array of 1..MAX where i declared max as a integer and i put get MAX.
[syntax="turing"]
Please specify what version of Turing you are using
1.1.4 i believe |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
andrew.
|
Posted: Mon Jan 18, 2010 7:55 pm Post subject: RE:Help!! Generating Prime Numbers |
|
|
1. You don't need to use arrays here. What you need to use is a for loop from 1..MAX
2. Turing 1.1.4 is extremely old, so download the latest version. The link is at the top of the site.
3. Write down on paper what a prime number is and how you know.
4. Once you do that, try to program it. Hint: using your for loop, you can check each number if it's a prime or not using the method you came up with in #3.
5. Once it's all working, try and optimize it a bit by cutting out numbers you don't need to check (e.g. all numbers that repeat by 2) |
|
|
|
|
 |
xSonu
|
Posted: Mon Jan 18, 2010 8:09 pm Post subject: RE:Help!! Generating Prime Numbers |
|
|
I am, sorry but i do not get what you are trying to say. As i am a Begginner at this. and never used for loop.
This is what i did
var MAX: int
get MAX
var prime: array 1..99999 of int
for i: 1..99999
prime(i):= 1 + (i)
exit when prime(i)= MAX or prime(i)>MAX
put prime(i)
end for
I dont know how to make the array infinite, and i dont know how to remove the numbers.
And please check if this is right so far. |
|
|
|
|
 |
Turing_Gamer

|
Posted: Mon Jan 18, 2010 9:45 pm Post subject: Re: Help!! Generating Prime Numbers |
|
|
Please use the find button. This topic has been brought up a lot. There are some well developed subjects, BTW.
I searched them before. There were a couple with for loop explanations.
Note : You need to use 2 for loops, one within the other |
|
|
|
|
 |
|
|