Jumat, 19 April 2013

Menghitung Bilangan Ganjil dan Genap Menggunakan Turbo Pascal

Berikut ini adalah program untuk menghitung bilangan ganjil dan genap, yang dimasukkan dalam bentuk tabel.

Lihat Output programnya:






Lihat Source codenya :

program Rojear;
uses wincrt;
var
j_ganjil, j_genap, b_ganjil, b_genap : integer;
jum, bil, b, x: integer;

begin
writeln('***************************************************************');
writeln('     Program Menghitung Bilangan Ganjil dan Bilangan Genap     ');
writeln('       Proses Akan Berhenti Jika Bilangan sama dengan 10       ');
writeln('***************************************************************');
writeln;
writeln('[-------][------------][------------][-----------][-----------]');
writeln('[  Bil  ][  J.Ganjil  ][  B.Ganjil  ][  J.Genap  ][  B.Genap  ]');
writeln('[-------][------------][------------][-----------][-----------]');
gotoxy(4,9);readln(bil);
        writeln;
	
	    if bil mod 2 <> 0 then
	    b:= bil;
	    if bil mod 2 <> 0 then
	    jum:=1;
	    if bil mod 2 = 0 then
	    b:=0;
	    if bil mod 2 = 0 then
            jum:=0;

	    j_ganjil:= b + j_ganjil;
	    b_ganjil:= jum + b_ganjil;

	    gotoxy(17,9);write(b);
	    gotoxy(30,9);write(jum);
	
	    if bil mod 2 = 0 then
	    b:= bil;
	    if bil mod 2 = 0 then
	    jum:=1;
	    if bil mod 2 <> 0 then
            b:=0;
	    if bil mod 2 <> 0 then
	    jum:=0;

	    j_genap:= b + j_genap;
	    b_genap:= jum + b_genap;

	    gotoxy(44,9);write(b);
	    gotoxy(57,9);write(jum);

	    gotoxy(1,9);write('[');
	    gotoxy(9,9);write(']');
	    gotoxy(10,9);write('[');
	    gotoxy(23,9);write(']');
	    gotoxy(24,9);write('[');
	    gotoxy(37,9);write(']');
	    gotoxy(38,9);write('[');
	    gotoxy(50,9);write(']');
	    gotoxy(51,9);write('[');
	    gotoxy(63,9);writeln(']');


    while bil <> 10 do
    begin
        x:=x+1;
	gotoxy(4,9+x);readln(bil);
        
	begin
	    if bil mod 2 <> 0 then
	    b:= bil;
	    if bil mod 2 <> 0 then
	    jum:=1;
	    if bil mod 2 = 0 then
	    b:=0;
	    if bil mod 2 = 0 then
            jum:=0;

	    j_ganjil:= b + j_ganjil;
	    b_ganjil:= jum + b_ganjil;

	    gotoxy(17,9+x);write(b);
	    gotoxy(30,9+x);write(jum);
	end;

        begin
	    if bil mod 2 = 0 then
	    b:= bil;
	    if bil mod 2 = 0 then
	    jum:=1;
	    if bil mod 2 <> 0 then
            b:=0;
	    if bil mod 2 <> 0 then
	    jum:=0;

	    j_genap:= b + j_genap;
	    b_genap:= jum + b_genap;

	    gotoxy(44,9+x);write(b);
	    gotoxy(57,9+x);write(jum);
	end;
	    gotoxy(1,9+x);write('[');
	    gotoxy(9,9+x);write(']');
	    gotoxy(10,9+x);write('[');
	    gotoxy(23,9+x);write(']');
	    gotoxy(24,9+x);write('[');
	    gotoxy(37,9+x);write(']');
	    gotoxy(38,9+x);write('[');
	    gotoxy(50,9+x);write(']');
	    gotoxy(51,9+x);write('[');
	    gotoxy(63,9+x);writeln(']');
     end;
writeln('[-------][------------][------------][-----------][-----------]');
writeln(' Jumlah',j_ganjil:11,b_ganjil:12,j_genap:15,b_genap:12);

end.

Artikel Terkait:

Share this article now on :

Posting Komentar

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( :-p =))