Senin, 22 April 2013

Program Pascal Perulangan untuk Menghitung Rata-rata Bilangan Ganjil dengan Input Bilangan Awal dan Akhir


For...to...do
program for_to_do;
uses wincrt;
label back;
var
 i:byte;
 k,awal,akhir:integer;
 rata,jum:real;
begin
back:
clrscr;
write('nilai awal=');readln(awal);
write('nilai akhir=');readln(akhir);
if awal<=akhir then
begin
for i:=awal to akhir do
if i mod 2=1 then
begin
jum:=jum+i;
awal:=awal+2;
k:=k+1;
end;
end
else goto back;
rata:=jum/k;
writeln('rata-rata=',rata:2:2);
end.

While...do

program while_do;

uses wincrt;

label back;

var
 k,awal,akhir:integer;
 rata,jum:real;
begin
back:
clrscr;
write('nilai awal=');readln(awal);
write('nilai akhir=');readln(akhir);
if awal<=akhir then
begin
while awal<=akhir do
begin
jum:=jum+awal;
awal:=awal+2;
k:=k+1;
end;
end
else goto back;
rata:=jum/k;
writeln('rata-rata=',rata:2:2);
end.


Repeat...Until

program repeat_until;
uses wincrt;
label back;
var
 k,awal,akhir:integer;
 rata,jum:real;
begin
back:
clrscr;
write('nilai awal=');readln(awal);
write('nilai akhir=');readln(akhir);
if awal<=akhir then
begin
repeat
jum:=jum+awal;
awal:=awal+2;
k:=k+1;
until awal>akhir;
end
else goto back;
rata:=jum/k;
writeln('rata-rata=',rata:2:2);
end.





2 komentar:

Riswan Hermawan mengatakan...

Ass, Maf mba sebelumnya.
saya punya kisi-kisi algoritma buat UPM tapi ngga bisa ngisinya,please mba bantu saya.

Riswan Hermawan mengatakan...

Maaf berkomentar menggunakan link tapi ini soalnya mba,

https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-prn2/v/1600214_717790258232237_875421409_n.jpg?oh=5e6b392e3ba493caddf915aae604aee5&oe=52D6F986&__gda__=1389816618_ac10c000ec763bcda9bf33d5806629ac

Posting Komentar

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Baca Selengkapnya Di : http://indonesianblog-jmk.blogspot.com/2012/06/cara-membuat-komentar-admin-berbeda.html#ixzz2kb6khEJE