{I was inspired to write this program while I was lying in bed trying to fall asleep. I suddenly had this great idea and here it is! } program findprimes(input, output); uses crt; type LPointer = ^List; List = record Number: integer; link: LPointer; end; var Head: LPointer; I, numprimes: integer; Procedure InitList; begin new(Head); Head^.Number := 2; Head^.Link := nil; end; Procedure AddOne(Num: integer; AfterMe: LPointer); var PNew: LPointer; begin new(PNew); PNew^.Number := num; PNew^.Link := nil; AfterMe^.Link := Pnew; end; Procedure IsPrime(I: integer; TestAgainst: LPointer); var temp: boolean; begin temp := ((I mod TestAgainst^.Number) = 0); {see if it goes in evenly} If temp = true then begin { Writeln(I, ': false (', TestAgainst^.Number, ')'); }end else begin if (TestAgainst^.Link = nil) {or (TestAgainst^.Number > sqrt(i) + 1)} then begin Inc(NumPrimes); Writeln(I, ': true'); AddOne(I, TestAgainst); {problem here} end else begin IsPrime(I, TestAgainst^.Link); end; end; end; Begin ClrScr; InitList; For I := 2 to 100 do begin IsPrime(I, Head); If ((I mod 24) = 0) then ReadKey; end; writeln('Total: ', NumPrimes); Readkey; end.