Kamis, 15 Desember 2011

Contoh Program Konversi

CONTOH PROGRAM KONVERSI BINER KE ANGKA
Program konversi_biner;
uses wincrt;
var   
     desimal,b,sisa,biner:integer;
begin
     write (' angka biner '); readln (biner);
    b:=0;
      repeat 
     sisa:= biner mod 10;
     biner:= biner div 10;
     if (b=0) then
     b:=1
     else
     b:=b*2;
    desimal:= desimal+sisa*b;
     until biner = 0;

      write ('desimal=', desimal );
    
end.



CONTOH PROGRAM KONVERSI ANGKA KE BINER
Program konversi_biner;
uses wincrt;
var   
     desimal,d,sisa,biner:integer;
begin
     write (' angka desimal '); readln (desimal);
     d:=0;
      repeat
     sisa:= desimal mod 2;
     desimal:= desimal div 2;
     if (d=0) then
     d:=1
     else
     d:=d*10;
     biner := biner+sisa*d;
     until desimal = 0;

      write ('biner=', biner );
    
end.



CONTOH PROGRAM KONVERSI JAM KE DETIK
program konversi_jam_ke_detik;
uses wincrt;
var
jam:real;
detik:real;
begin
write('masukkan jam=');
readln(jam);
detik:=jam*3600;
writeln('total detik=',detik:10:2);
end.



CONTOH PROGRAM KONVERSI DETIK KE JAM
program konversi_detik_ke_jam;
uses wincrt;
var
detik:real;
jam:real;
begin
write('masukkan detik=');
readln(detik);
jam:=detik/3600;
writeln('jam=',jam:10:2);
end.



CONTOH PROGRAM KONVERSI SUHU
Program suhu;
uses wincrt;
var
celcius,kelvin:integer;
fahrenheit:real;
begin
write('Masukkan suhu dalam celcius = ');readln(celcius);
fahrenheit:=(9/5*celcius)+32;
kelvin:=celcius+273;
writeln('Suhu dalam fahrenheit = ',fahrenheit:5:2);
writeln('Suhu dalam kelvin = ',kelvin);
end.



CONTOH PROGRAM KONVERSI NILAI KE HURUF METODE IF ELSE
program konversi_nilai_ke_huruf;
uses wincrt;
var
nilai:real;
begin
write('masukkan nilai : ');readln(nilai);
if (nilai>=81) and (nilai <=100) then writeln ('hasil:=A')
else if (nilai>=76) and (nilai<=80) then writeln ('hasil:=AB')
else if (nilai >=71) and (nilai<=75) then writeln ('hasil:=B')
else if (nilai >=66) and (nilai<=70) then writeln ('hasil:=BC')
else if (nilai >=61) and (nilai<=65) then writeln ('hasil:=C')
else if (nilai >=41) and (nilai<=60) then writeln ('hasil:=D')
else writeln('hasil:=E');

end.


CONTOH PROGRAM KONVERSI NILAI KE HURUF METODE CASE OF
program menghitung_nilai;
uses wincrt;
var
a:integer;
begin
readln(a);
case a of 81..100 : writeln ('A');
 76..80 : writeln ('AB');
 71..75 : writeln ('B');
 61..70 : writeln ('BC');
 51..60 : writeln ('C');
 41..50 : writeln ('D');
 0..40 : writeln ('E');
else writeln ('input nilai salah');
end;
end.

Tidak ada komentar:

Posting Komentar

 
;