Help! i need it!!!

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 1
Reputation: mscerri is an unknown quantity at this point 
Solved Threads: 0
mscerri mscerri is offline Offline
Newbie Poster

Help! i need it!!!

 
0
  #1
Nov 26th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 213
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Help! i need it!!!

 
0
  #2
Dec 2nd, 2006
Why 541? 100 should be enough to store a hundred primes...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Pascal and Delphi Forum
Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC