Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Prime Number Finder
Author Message
TheXploder

Posted: Fri Feb 20, 2004 12:39 pm   Post subject: Prime Number Finder

Here is a program that finds prime numbers (divisible by itself and 1):

 code: var c, number : int := 0 loop     for decreasing i : number - 1 .. 2         if number mod i > 0 then             c := c + 1         end if     end for     if c = number - 2 then         put "Number: ", number, ", Prime number."         c := 0     else         put "Number: ", number, ", is not a Prime number."         c := 0     end if     number := number + 1     delay(10) end loop

This could be sead up a bit, if I cancel out all numbers with a 5 or 0 at the end, or the numbers that are divisible by a previous prime number, can't be prime anymore...

I used this website to check them aswell: http://www.utm.edu/research/primes/lists/small/1000.txt

If you like please play around with it and try to beat me at finding the prime numbers: I am currently at prime number: 12739

ohh, wait: 16229

Tony

Posted: Fri Feb 20, 2004 2:10 pm   Post subject: (No subject)

maybe you should check out this tutorial
Tony's programming blog. DWITE - a programming contest.
the_short1

Posted: Sat Feb 21, 2004 11:11 pm   Post subject: (No subject)

hahah... yea Tony's prog... it worked in 12 sec to produce to 1million

produces a text file will all prime numbers in it...
from 2 > million
(with a 120 MHZ peice of crap)

WOW... that post is old too... 1y... at time when admins didnl;t have steady 2000 bits
TheXploder

Posted: Sat Feb 21, 2004 11:46 pm   Post subject: (No subject)

thanx for that program Tony...
Andy

Posted: Sun Feb 22, 2004 2:00 pm   Post subject: (No subject)

if u want a really good one, do some string manipulation, so u can store 255 digit numbers
Tony

Posted: Sun Feb 22, 2004 11:47 pm   Post subject: (No subject)

why not just use a char array then? you can make your arrays much larger then 255
Tony's programming blog. DWITE - a programming contest.
Andy

Posted: Mon Feb 23, 2004 10:49 am   Post subject: (No subject)

good point
Andy

Posted: Mon Feb 23, 2004 10:50 am   Post subject: (No subject)

how about a flexiable array of strings?

rizzix

Posted: Tue Feb 24, 2004 11:59 pm   Post subject: (No subject)

aah but turing arrays have a limit of 1M elements.

using a string class i created will let u manipulate on an infinite number of characters. (or maybe untill u exhaust all the free memory in RAM)
Tony

Posted: Wed Feb 25, 2004 12:58 am   Post subject: (No subject)

you can always start writing numbers down on your harddrive
Tony's programming blog. DWITE - a programming contest.
BlAcK TuRtLe

Posted: Sun Feb 29, 2004 2:34 pm   Post subject: (No subject)

This is a variation of your code which lets the user enter a number then finds out whether or not its prime.
 code: var x, num : int := 0 loop     put "Enter a number(-99 to exit)"     get num     exit when num = -99     for decreasing y : num - 1 .. 2         if num mod y > 0 then             x := x + 1         end if     end for     if x = num - 2 then         put num, ", is a prime number."         x := 0     else         put num, ", is not a Prime number."         x := 0     end if     delay (2000)     cls end loop cls
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 11 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: