3/20/11

Pascal programs for primes

This is pascal script to find primes from (a) to (b).


uses wincrt;
var
a,b,x,y : integer;
hasil1 : longint;
again,primes: boolean;
begin
again:=true;
repeat
  begin
    write('Count primes from');read(a);write('to');readln(b);
    for x:=a to b do
     begin
      primes :=true;
      for y:=2 to x-1 do
       begin
       if (x mod y)=0 then
        begin
         primes:=false;
        end;
       end;
      if primes then write (x:5);
     end;
   end;
end;
readln;
until not again;
end.

No comments:

Post a Comment