Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

pascal

Program orderBySimpleValue(output);
var initialArray,outputArray:  array[1..10] of integer;
var collectArray: array[1..3,1..10] of integer;
var n:integer;
function isSimple(n:integer):boolean;
var t:boolean;
  var i:integer;
  begin
    t :=true;
    if n<2 then begin
        isSimple:=false;
        exit;
    end;
	for i:= 2 to n-1 do
	
     begin
  		if (n mod i) = 0  then
        begin
            t :=false;
            break;
        end;
        
      end;
     isSimple :=t;
  end;
procedure input();
    var i:integer;
    begin
        for i:=1 to n do begin
            initialArray[i] := Random(30)+5;
            writeln(initialArray[i]);
            end;
    end;
procedure getCollectArray();
    var i,firstSimple, k1, k2, k3:integer;
    begin
        firstSimple := 0;
        k1:=1;
        k2:=1;
        k3:=1;
        for i:=1 to n do
            if (firstSimple = 0) and (isSimple(initialArray[i]) ) then 
            begin    
                firstSimple := initialArray[i];
                break;
            end;
        for i:=1 to n do
            begin
                if initialArray[i] < firstSimple then begin 
                    collectArray[1][k1]:= initialArray[i];
                    k1:=k1+1;
                end;
                if initialArray[i] = firstSimple then begin 
                    collectArray[2][k2]:=initialArray[i];
                    k2:=k2+1;
                end;
                if initialArray[i] > firstSimple then begin 
                    collectArray[3][k3]:=initialArray[i];
                    k3:=k3+1;
                end;
            end;
            writeln('simple', firstSimple);
    end;
    
    procedure outputResult();
        var i,j,outputIndex:integer;
        begin
        outputIndex:= 1;
        for i := 1 to 3 do
            for j:=1 to n do begin 
                if collectArray[i][j] = 0 then break;
                outputArray[outputIndex]:= collectArray[i][j];
                writeln(outputArray[outputIndex]);
                outputIndex := outputIndex + 1;
                
            end; 
        end;
begin
  n:=10;
  input();
  getCollectArray();
  outputResult();
end.

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.