Contoh Program Himpunan
uses wincrt;
var
a,b,c,d,e,f,g,h: integer;
k,w :char;
pilih: integer;
procedure input;
begin
clrscr;
write('Masukan Nilai n(A) :');readln(a);
write('Masukan Nilai n(B) :');readln(b);
write('Masukan Nilai n(C) :');readln(c);
write('Masukan Nilai n(A n B) :');readln(d);
write('Masukan Nilai n(B n C) :');readln(e);
write('Masukan Nilai n(A n C) :');readln(f);
write('Masukan Nilai n(A n B n C) :');readln(g);
end;
procedure hitung;
begin
h:=a+b+c-d-e-f+g;
if h<=0 then
else writeln('error');
end;
procedure output;
begin
k:='y';
while (k='y') or (k='Y') do
begin
clrscr;
write('n(A u B u C)=n(A)+n(B)+n(C)-n(A n B)-n(B n C)-n(A n C)+n(A n B n C)');writeln;
write(h,'=',a,'+',b,'+',c,'-',d,'-',e,'-',f,'+',g);writeln;
writeln('pilihan: ');
writeln('A. n(A)');
writeln('B. n(B)');
writeln('C. n(C)');
writeln('D. n(A n B)');
writeln('E. n(B n C)');
writeln('F. n(A n C)');
writeln('G. n(A n B n C)');
writeln('---------------');
write('Masukkan Pilihan: ');readln(w);
case w of
'A','a':begin
writeln(a,'=',h,'-',b,'-',c,'+',d,'+',e,'+',f,'-',g);
end;
'B','b':begin
writeln(b,'=',h,'-',a,'-',c,'+',d,'+',e,'+',f,'-',g);
end;
'C','c':begin
writeln(c,'=',h,'-',a,'-',b,'+',d,'+',e,'+',f,'-',g);
end;
'D','d':begin
writeln(d,'=',a,'+',b,'+',c,'-',e,'-',f,'+',g,'-',h);
end;
'E','e':begin
writeln(e,'=',a,'+',b,'+',c,'-',d,'-',f,'+',g,'-',h);
end;
'F','f':begin
writeln(f,'=',a,'+',b,'+',c,'-',d,'-',e,'+',g,'-',h);
end;
'G','g':begin
writeln(g,'=',h,'-',a,'-',b,'-',c,'+',d,'+',e,'+',f);
end;
else writeln('Salah Input!!');
write('Ulang (y/t):');readln(k);
end;
readln;
end;
end;
begin
repeat
clrscr;
writeln(' MENU UTAMA ');
writeln('=============');
writeln(' 1. INPUT ');
writeln(' 2. OUTPUT ');
writeln('=============');
write('pilih <0 :keluar> : '); readln(pilih);
case pilih of
1 : input;
2 :
begin
hitung;
output;
end
end;
until pilih=0;
end.
end.
end.
0 komentar:
Posting Komentar