Welcome to WebmasterWorld Guest from 54.196.243.192

Forum Moderators: phranque

Message Too Old, No Replies

pls help write a pascal program to find the prime numbers btw 1 and 200

     
3:46 pm on Feb 8, 2010 (gmt 0)

New User

5+ Year Member

joined:May 29, 2009
posts:22
votes: 0


pls i was given these assignment at school and i would be having a test on dis course tomorrow.pls it is very urgent.would appreciate it if any1 could help me write a pascal program to find the prime numbers between 1 and 200.
4:06 pm on Feb 8, 2010 (gmt 0)

Preferred Member

10+ Year Member

joined:July 28, 2000
posts:580
votes: 0


Not pascal but rexx.


do i=1 to 200
p=0
do j=1 to i until p > 2
if i // j = 0 then
p=p+1
end
if p=2 then
say i' is prime'
end


You didn't think anyone was going to hand it to you on a plate did you :-)
1:18 am on Feb 9, 2010 (gmt 0)

Senior Member from KZ 

WebmasterWorld Senior Member lammert is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 10, 2005
posts:2886
votes: 1


This is the fastest and smallest Pascal implementation I can think of. I don't know if they will accept it. It should be accepted though because the output of the program fits the assignment.

BEGIN
WriteLn( '2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,73,79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199' );
END
3:05 am on Feb 9, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:May 31, 2005
posts:1108
votes: 0


They still teach pascal? Wow.
I wrote a program like that over 20 years ago.

Just do a search in your favourite search engine for pascal prime number and I'm sure you will find some (I did, and the code was published in 1990).
But doing that defeats the purpose of doing it yourself, as you will learn things from doing it, rather than copying someone else. So if you want to actually become a programmer, try and do it yourself, or at the very least make sure you understand the code you download fully.