Thursday, 13 December 2012

Jawaban Midterm Algoritma Pemograman I STT-BCI

JAWABAN MIDTERM ALGORITMA PEMOGRAMAN I

Dosen Pengasuh : Drs. Agus Wahyuni, ST. M.Pd

 

 

JAWABAN


1. Perbaikannya sebagai berikut!

 

Program contoh4;

Uses crt;

Var i,n,x:integer;

Begin

CLRSCR;

  Writeln('Program Faktorial');

  Writeln('=================');

  Writeln;

  Write('Masukkan Nilai Faktorial: ');Readln(n);

  Writeln;

  if (n<=0) then

    Writeln('Hasil Faktorial: ',1)

  else

    Begin

      x:=1;

      For i := 1 to n do

          x:=x*i;

      Writeln('Hasil Faktorial: ',x);

    End;

    READLN;

End.

 

2.       Programnya Sebagai Berikut:

a.       Program EKinetik;

Uses crt;

Var EK,m,v :real;

Begin

Clrscr;

Writeln(‘nilai m:’);readln(m);

Writeln(‘nilai v:’); readln(v);

Ek:=0.5*m*SQR(v);

Writeln(EK:3:2);

Readln;

End.

 

b.      Program konstanta;

Uses crt;

Var K,q1,q2,r :real;

Begin

Clrscr;

Writeln(‘nilai q1:’);readln(q1);

Writeln(‘nilai q2:’); readln(q2);

Writeln(‘nilai r:’);readln(r);

k:=(q1*q2)/Sqr(r);

Writeln(K:3:2);

Readln;

End.

 

c.       Program konstanta;

Uses crt;

Var v,m,v1,r :real;

Begin

Clrscr;

Writeln(‘nilai m:’);readln(m);

Writeln(‘nilai v1:’); readln(v1);

Writeln(‘nilai r:’);readln(r);

v:=(m*Sqr(v1))/r;

Writeln(v:3:2);

Readln;

End.

 

 

3.       Program Pilihan;

Uses crt;

Var k,ek,q1,q1,r,m,v :real;

Pilih : char;

Begin

Clrscr;

Writeln (‘1. Program 1’);

Writeln(‘2. Program 2’);

Writeln(‘masukkan pilihan:’); readln(pilih);

Case pilih of

‘1’ : begin

Writeln(‘nilai q1:’);readln(q1);

Writeln(‘nilai q2:’); readln(q2);

Writeln(‘nilai r:’);readln(r);

k:=(q1*q2)/Sqr(r);

Writeln(K:3:2);

End;

 

‘2’: begin

Clrscr;

Writeln(‘nilai q1:’);readln(q1);

Writeln(‘nilai q2:’); readln(q2);

Writeln(‘nilai r:’);readln(r);

k:=(q1*q2)/Sqr(r);

Writeln(K:3:2);

End;

End;

                Readln;

End.

 

 

4. PROGRAM iterasi;

USES CRT;

VAR A,B,C,D: INTEGER;

BEGIN

CLRSCR;

WRITELN('==================');  {pernyataan}

WRITELN(' A   B    C    D  ');  {pernyataan}

WRITELN('==================');  {pernyataan}

c:=1;

while C<6 do

begin

A:=C+C;  {pernyataan}

B:=A-1;

D:=A+B+C;       {pernyataan}

writeln(    A:10,B:10,C:10,D:10);

C:=C+1;

end;

readln;

end.

 

5.         Program nilai1;

Uses crt;

Var nilai : integer;

Begin

Clrscr;

Writeln(‘masukkan nilai didapat: ‘); readln(nilai);

If nilai>=87 then

Writeln(‘A’)

Else

If nilai>=80 then

Writeln(‘B+’)

Else

If nilai>=76 then

Writeln(‘B’)

else

If nilai>=70 then

Writeln(‘C+’)

else

If nilai>=65 then

Writeln(‘C’)

else

If nilai>=60 then

Writeln(‘D’)

Else

Writeln(‘E’);

Readln;

End.

 

 

 

0 komentar: