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

#### mailtimi

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

#### New User

joined:May 29, 2009
posts:22

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.

#### mark_roach

4:06 pm on Feb 8, 2010 (gmt 0)

#### Preferred Member

joined:July 28, 2000
posts:580

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 :-)

#### lammert

1:18 am on Feb 9, 2010 (gmt 0)

#### Senior Member from KZ

joined:Jan 10, 2005
posts:2886

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

#### Dijkgraaf

3:05 am on Feb 9, 2010 (gmt 0)

#### Senior Member

joined:May 31, 2005
posts:1108

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.