944,035 Members | Top Members by Rank

Ad:
Nov 26th, 2006
0

Help! i need it!!!

Expand Post »
hi everyone;
i am doing a project for my sis in unversity, and it says that i have to find the first 100 prime numbers and store them in an array.
i managed to find the prime numbers but when i try to store it in an array a bunch of other numbers come up, can you tell me what i am doing wrong? below is the code. pls help me.
then i have to change the prime numbers into either hex, octal, binary and decimal. i need help with this to.
thanks.
Pascal and Delphi Syntax (Toggle Plain Text)
  1. Program Assignment;
  2.  
  3. Uses
  4. crt;
  5.  
  6. Var
  7. cOption: char;
  8. aPrime: array [1..541] of longint;
  9. iPrime,range: longint;
  10. cnt: integer;
  11.  
  12. Procedure Prime;
  13. Var
  14. y,temp: longint;
  15. root: real;
  16. introot,count: longint;
  17. prime: boolean;
  18. Begin
  19. clrscr;
  20. cnt := 0;
  21. range := 541;
  22. for iPrime:= 2 to range do
  23. begin
  24. root:= int(sqrt(iPrime));
  25. introot:=round(root);
  26. prime:= true;
  27. for y:=2 to introot do
  28. Begin
  29. if iPrime mod y = 0 then
  30. prime := false;
  31. End;
  32. if prime= true then
  33. Begin
  34. cnt := cnt + 1;
  35. write(iPrime,' ');
  36. aPrime[cnt] := iPrime;
  37. End;
  38. End;
  39. readln;
  40. End;
  41.  
  42. Procedure ViewPrime;
  43. Begin
  44. clrscr;
  45. cnt := 0;
  46. Writeln('²²²²²² View Prime ²²²²²²');
  47. Writeln;
  48. For iPrime:= 2 to range do
  49. Begin
  50. cnt := cnt + 1;
  51. write(aPrime[cnt],' ');
  52. End;
  53. Readln;
  54. End;
  55.  
  56. BEGIN
  57. clrscr;
  58. Prime;
  59. END.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mscerri is offline Offline
1 posts
since Nov 2006
Dec 2nd, 2006
0

Re: Help! i need it!!!

Why 541? 100 should be enough to store a hundred primes...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: Team speek help
Next Thread in Pascal and Delphi Forum Timeline: pascal help!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC