Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Prime number counter
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
aussilia




PostPosted: Mon Jun 27, 2005 2:08 pm   Post subject: Prime number counter

This is my first ever time using Turing to make my own program! Very Happy
I basically learned all I know so far from this site.
Anyway, I remember a math problem when I had to find the first 20 prime numbers. Evil or Very Mad
It was very annoying and I hated it.
So I made a prime number counter that lists all the prime numbers from 1 to whatever you want Idea

Turing:

var x1, y1 : int
var winID1 : int
var font1:int
font1 := Font.New ("comicsans:60")

var y := 100 % put the number you want to go up to. ************

var test : int
var primes : array  1 .. y of int
var res : int
primes (1) := 3
primes (2) := 5
primes (3) := 7
var next : int := 3
        for i : 9 .. y by 2

test := 0
for j : 1..next
res := round(i/primes(j))* primes (j)
if res not= i
then
test := test+1
end if
end for
if test = next
then
next := next +1
primes (next) := i
put primes (next)

end if
end for

winID1 := Window.Open ("graphics:600;400;nobuttonbar;position:center,center")

color (red)
delay (200)
Font.Draw ("Done", 1, 300, font1, blue)
delay (900)
put "Number of Prime numbers between 1 and " ..
put y ..
put ":"
put next
drawfillstar (100,100,200,200,green)


I used different stuff that I learned on this site.
I gave the program the first 3 primes, then i have it look at each odd number and try to divide it by the list of primes. If it divides, it is not prime so it is not listed, if it does not divide, it is prime so it is added to the list. The process then re-starts with a new longer list of primes.

If i have made a mistake, Please tell me!

I have a question, how can I make it so that I can scroll up and down the list of numbers?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Jun 27, 2005 2:14 pm   Post subject: (No subject)

good start.

Now it would be even better to post this in [Turing Source Code] and use [code][/code] or better yet [syntax="turing"][/syntax] tags.

Smile
Mazer




PostPosted: Tue Jun 28, 2005 7:49 am   Post subject: Re: Prime number counter

aussilia wrote:
I have a question, how can I make it so that I can scroll up and down the list of numbers?

At the very beginning of your program:
code:
setscreen("text")
Delos




PostPosted: Thu Jun 30, 2005 3:08 pm   Post subject: (No subject)

No need for you to post 2 seperate threads.
Clean this one up (add [code] or [syntax] tags, and I'll move it to Source Code).
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: