Simplified Example Pascal Program
Uses WinCrt;
Var
X,Y,Rx,Ry,Jx,Jy : real;
Nx,Ny,i : integer;
Begin
ClrScr;
Write(‘Masukkan Banyaknya X :’);Readln(Nx);
Write(‘Masukkan Banyaknya Y :’);Readln(Ny);
If Nx = Ny then
For i:=1 to Nx Do
begin
Write(‘Data X ke-’,i,’ = ‘);Readln(X);
Write(‘Data Y ke-’,i,’ = ‘);Readln(Y);
Jx:=Jx+X;
Jy:=Jy+Y;
end
else if Nx > Ny then
begin
For i:=1 to Ny Do
begin
Write(‘Data X ke-’,i,’ = ‘);Readln(X);
Write(‘Data Y ke-’,i,’ = ‘);Readln(Y);
Jx:=Jx+X;
Jy:=Jy+Y;
end;
i:=Ny+1;
Repeat
Write(‘Data X ke-’,i,’ = ‘);Readln(X);
Jx:=Jx+X;
i:=i+1;
until i>Nx;
end
else if Nx < Ny then begin For i:=1 to Nx Do begin Write(‘Data X ke-’,i,’ = ‘);Readln(X); Write(‘Data Y ke-’,i,’ = ‘);Readln(Y); Jx:=Jx+X; Jy:=Jy+Y; end; i:=Nx+1; Repeat Write(‘Data Y ke-’,i,’ = ‘);Readln(Y); Jy:=Jy+Y; i:=i+1; until i>Ny;
end;
Rx:=Jx/Nx;
Ry:=Jy/Ny;
writeln(‘Rata-rata dari data X = ‘,Rx:6:2);
writeln(‘Rata-rata dari data Y = ‘,Ry:6:2);
end.
Program ganjil_genap;
uses wincrt;
var
bil, i,g1,g2,j1,j2,n: integer;
rt1,rt2:real;
begin
write(‘Masukkan Banyaknya Data ‘ );readln(n);
for i := 1 to n do
begin
write(‘Bilangan ke:’,i ,’ ‘);readln(bil);
if bil mod 2 = 0 then
j1:=j1 +1;
g1:=g1+bil;
if bil mod 2 =1 then
j2:=j2+1;
g2:=g2+bil;
end;
rt1:=g1/j1;
rt2:=g2/j2;
writeln(‘Jumlah bil. Ganjil=’ ,j2);
writeln(‘Jumlah bil. Genap=’ ,j1);
writeln(‘Rerata Ganjil=’ ,rt2:4:2);
writeln(‘Rerata Genap=’ ,rt1:4:2);
end.