| | |
Urgent Help needed with Pascal programming
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi everyone,
I need some help in the following task:
I am writing a Pascal program that will
1). find the first 100 prime numbers and store them in an array.
2). give a choice to the user, who will choose which number base the prime numbers will be displayed in (I have to validate this entry, so only valid choices may be made). Then display the prime numbers in the requested base (base 10-decimal, base 2-binary, base 8-octal or base 16-hex).
3). quit the program when the option to quit is chosen.
The thing is that I managed to do only the first part of the program and I don't know how to continue the two other parts. If anyone is willing to help me, I would be grateful...Thank you in advance.
The first part of the program that I managed to do is the following:
Program Prime_Numbers;
uses crt;
Var
limit: longint;
p: array[1..52441] of boolean;
i, n : longint;
c:integer;
Begin
clrscr;
limit:= 52441; {search limit}
{assume all numbers are prime at first}
for n:=2 to limit do p[n]:= true;
{eliminate multiples of each pair}
for n:= 2 to Round(SQRT(limit)) do
IF p[n] Then
BEGIN
i := 0;
REPEAT
p[n * n + I * n] := false;
i := I + 1;
Until
n *n+i*n > limit;
End;
c:= 0;
for n:= 2 to limit Do
if p[n] And (c<100) Then
Begin
WriteLn(n);
c:=c+1;
end;
Readln;
End.
I need some help in the following task:
I am writing a Pascal program that will
1). find the first 100 prime numbers and store them in an array.
2). give a choice to the user, who will choose which number base the prime numbers will be displayed in (I have to validate this entry, so only valid choices may be made). Then display the prime numbers in the requested base (base 10-decimal, base 2-binary, base 8-octal or base 16-hex).
3). quit the program when the option to quit is chosen.
The thing is that I managed to do only the first part of the program and I don't know how to continue the two other parts. If anyone is willing to help me, I would be grateful...Thank you in advance.
The first part of the program that I managed to do is the following:
Program Prime_Numbers;
uses crt;
Var
limit: longint;
p: array[1..52441] of boolean;
i, n : longint;
c:integer;
Begin
clrscr;
limit:= 52441; {search limit}
{assume all numbers are prime at first}
for n:=2 to limit do p[n]:= true;
{eliminate multiples of each pair}
for n:= 2 to Round(SQRT(limit)) do
IF p[n] Then
BEGIN
i := 0;
REPEAT
p[n * n + I * n] := false;
i := I + 1;
Until
n *n+i*n > limit;
End;
c:= 0;
for n:= 2 to limit Do
if p[n] And (c<100) Then
Begin
WriteLn(n);
c:=c+1;
end;
Readln;
End.
The second is easy. Pascal has built in libraries to convert numbers between bases, just use those.
The third is also easy, once you set up the structure of the program correctly.
At the moment you don't do anything to let the user choose what to do. Write that first.
The third is also easy, once you set up the structure of the program correctly.
At the moment you don't do anything to let the user choose what to do. Write that first.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
•
•
Join Date: Dec 2006
Posts: 3
Reputation:
Solved Threads: 0
Hi jwenting,
Thanks for the help. I managed to set up the main menu, however, I haven't understood what I should do in order to convert the prime numbers into binary, octal and hexadecimal. I tried to set up a new array and use the mod function but the program didn't work properly. Could you help me please because I'm just stuck in this part? Thank you in advance.
Thanks for the help. I managed to set up the main menu, however, I haven't understood what I should do in order to convert the prime numbers into binary, octal and hexadecimal. I tried to set up a new array and use the mod function but the program didn't work properly. Could you help me please because I'm just stuck in this part? Thank you in advance.
![]() |
Similar Threads
- help please urgent review needed (Website Reviews)
- Urgent help needed (Pascal and Delphi)
- pascal write problem (ASP.NET)
- Pascal Programming Language Help (Legacy and Other Languages)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Synthesize a program
- Next Thread: Umm, I need some real help here please.
| Thread Tools | Search this Thread |
Tag cloud for Pascal and Delphi






