Untuk penjelasan percabangan dapat dibaca di postingan sebelumnya.
Program percabangan menggunakan if;
uses crt;
var
nilai : integer;
huruf : string;
begin
clrscr;
writeln('Program Percabangan');
writeln('===================');
write ('Input Nilai : ');
readln(nilai);
if (nilai>=0) and (nilai<56) then
huruf:='E';
if (nilai>55) and (nilai<66) then
huruf:='D';
if (nilai>65) and (nilai<76) then
huruf:='C';
if (nilai>75) and (nilai<86) then
huruf:='B';
if (nilai>85) and (nilai<101) then
huruf:='A';
writeln(huruf);
readkey;
end.
Program percanban dengan case :
Program percabangan;
uses crt;
var
nilai : integer;
huruf : string;
begin
clrscr;
writeln('Program Percabangan');
writeln('===================');
write ('Input Nilai : ');
readln(nilai);
case nilai of
0..55:huruf:='E';
56..65:huruf:='D';
66..75:huruf:='C';
76..85:huruf:='B';
86..100:huruf:='A';
else huruf:='E';
end;
writeln(huruf);
readkey;
end.
Program percabangan menggunakan if;
uses crt;
var
nilai : integer;
huruf : string;
begin
clrscr;
writeln('Program Percabangan');
writeln('===================');
write ('Input Nilai : ');
readln(nilai);
if (nilai>=0) and (nilai<56) then
huruf:='E';
if (nilai>55) and (nilai<66) then
huruf:='D';
if (nilai>65) and (nilai<76) then
huruf:='C';
if (nilai>75) and (nilai<86) then
huruf:='B';
if (nilai>85) and (nilai<101) then
huruf:='A';
writeln(huruf);
readkey;
end.
Program percanban dengan case :
Program percabangan;
uses crt;
var
nilai : integer;
huruf : string;
begin
clrscr;
writeln('Program Percabangan');
writeln('===================');
write ('Input Nilai : ');
readln(nilai);
case nilai of
0..55:huruf:='E';
56..65:huruf:='D';
66..75:huruf:='C';
76..85:huruf:='B';
86..100:huruf:='A';
else huruf:='E';
end;
writeln(huruf);
readkey;
end.
Post a Comment