OLEH:
KELOMPOK 9
DOSEN PENGAMPU:
2019
SOAL LATIHAN DAN JAWABAN BAB 6
1. Rancang program komputer untuk menentukan nilai P dari rumusan berikut jika nilai
2 a
a, b, c, dan d diketahui : P=a+b +
b+ d
Jawab:
1. Defenisi masalah
Menentukan nilai P
Rumus : P= a+b^2+(a/b+d)
Data input: a, b, c,d
Data Output : value of P
2. Struktur Data
3. Program Algoritma
a. Start
b. Input data
Input a
Input b
Input c
c. Process
x ← b+d;
if x~=0 then
P ← a+b^2+(a/b+d);
else x==0
P ← a+b^2+(a/b+d);
end
d. Output data
if x~=0
1
write ('The value of P is definite');
write(P);
else x==0
write('The value of P is infinite');
write(P);
end
e. Stop
%kelompok 9
%hileri
%4172121022
%riski
%4172121022
clc;
a=input(' Coef a= ');
b=input(' Coef b= ');
c=input(' Coef c= ');
d=input(' Coef d= ');
%process
x=b+d;
if x~=0
P= a+b^2+(a/b+d);
else x=0
P= a+b^2+(a/b+d);
end
%Output
if x~=0
disp('The value of P is definite');
fprintf('P =%0.2f \n',P);
else x=0
disp('The value of P is infinite');
fprintf('P =%0.2f \n',P);
2
end
5. Testing Program
Coef a= 2
Coef b= 3
Coef c= 4
Coef d= 5
x=0
The value of P is infinite
P = 16.67
2. Rancang program komputer untuk menentukan nilai P dari rumusan berikut jika nilai
a, b, c, dan d diketahui:
c a
P=b2 + +
b +d d
Jawab
1) Defenisi masalah
Menentukan nilai P
Rumus : P= b^2+(a/b+d)+(a/d)
Data input: a, b, c,d
Data Output : value of P
2) Structur Data
3
3) Algorithm Program
f. Start
g. Input data
Input a
Input b
Input c
h. Process
x ← b+d;
if x~=0 then
P ← b^2+(a/b+d)+(a/d);
else x==0
P ← b^2+(a/b+d)+(a/d);
end
i. Output data
if x~=0
write ('The value of P is definite');
write(P);
else x==0
write('The value of P is infinite');
write(P);
end
j. Stop
4) Coding in MatLab
%kelompok 9
%hileri
%4172121022
%riski
%4172121022
clc;
a=input(' Coef a= ');
b=input(' Coef b= ');
c=input(' Coef c= ');
4
d=input(' Coef d= ');
%process
x=b+d;
if x~=0
P= b^2+(a/b+d)+(a/d);
else x=0
P= b^2+(a/b+d)+(a/d);
end
%Output
if x~=0
disp('The value of P is definite');
fprintf('P =%0.3f \n',P);
else x=0
disp('The value of P is infinite');
fprintf('P =%0.3f \n',P);
end
5) Testing Program
Coef a= 1
Coef b= 2
Coef c= 3
Coef d= -1
The value of P is definite
P = 2.500
3. Rancang program komputer untuk menentukan nilai P dari rumusan berikut jika nilai
a, b, c, dan d diketahui: P=a+b2 + √ c−d
Jawab:
1) Defenisi Masalah
Menentukan nilai P
5
Rumus : P=a+ b^2+(sqrt c-d)
Data input: a, b, c,d
Data Output : value of P
2) Struktur Data
3) Algorithm Program
a. Start
b. Input data
Input a
Input b
Input c
c. Process
x ← c-d;
if x>0 then
P ← a+b^2+ sqrt(c-d);
Elseif x=0
P ← a+b^2+ sqrt(c-d);
else
P ← a+b^2+ sqrt(c-d);
end
d. Output data
if x>0
write ('The value of P is definite');
write(P);
elseif x=0
write('The value of P is definite');
write(P);
else
6
write('The value of P is infinite');
write(P);
end if
e. Stop
4) Coding in MatLab
%data input
clc;
a=input(' Coef a= ');
b=input(' Coef b= ');
c=input(' Coef c= ');
d=input(' Coef d= ');
%process
x=c-d;
if x>0
P=a+b^2+ sqrt(c-d);
elseif x==0
P=a+b^2+ sqrt(c-d);
else
Pc=a+b^2+ sqrt(c-d);
end
%Output
if x>0
disp('The value of P is definite');
fprintf('P =%0.3f \n',P);
elseif x==0
disp('The value of P is definite');
fprintf('P =%0.3f \n',P);
else
disp('The value of P is complex');
fprintf('P =%0.3f \n',P);disp(Pc);
end
7
5) Testing Program
Coef a= 3
Coef b= 3
Coef c= 5
Coef d= 1
The value of P is definite
P = 9.000
4. Rancang program komputer untuk menentukan besarnya gaya Coulomb dari dua
muatan dengan jarak r jika besar kedua muatan dan r diketahui
Jawab:
1) Problem Definition
k . q 1 .q 2
F=
Determine the value of P from the formula r2
2) Data Structure
3) Algorithm Program
a. Start
b. Input data
Input k
Input q1
Input q2
Input r
8
c. Process
x ← r;
if x>0 then
F ← k*q1*q2/(x^2);
end
d. Output data
if x>0
write ('The value of F');
write(F);
end if
e. Stop
4) Coding in MatLab
%data input
clc;
k=input(' k= ');
q1=input(' q1= ');
q2=input(' q2= ');
r=input(' r= ');
%process
x=r;
if x>0
F=k*q1*q2/(x^2);
end
%Output
if x>0
disp('The value of F');
fprintf('F =%6.3f \n',F); disp(['N']);
end
5) Testing Program
a) k= 9*(10^9)
q1= 4
9
q2= 6
r= 3
The value of F
F =24000000000.000 N
5. Rancang program komputer untuk menentukan besarnya kuat medan listrik dan
potensial listrik oleh muatan pada jarak tertentu dari muatan jika besar muatan dan
jarak diketahui
Jawab:\
1) Problem Definition
k .q
E=
Determine the value of P from the formula r2
Input koef : k, q, r
Output : value of E
2) Data Structure
3) Algorithm Program
a. Start
b. Input data
Input k
Input q
Input r
c. Process
x ← r;
if x>0 then
E ← k*q/(x^2);
end
d. Output data
if x>0
10
write ('The value of E');
write(E);
end if
e. Stop
4) Coding in MatLab
%data input
clc;
k=input(' k= ');
q=input(' q= ');
r=input(' r= ');
%process
x=r;
if x>0
E=k*q/(x^2);
end
%Output
if x>0
disp('The value of E');
fprintf('E =0.2f \n',E); disp(['N/C']);
end
5) Testing Program
a) k= 9*(10^9)
q= 4
r= 2
The value of E
E =9000000000.00
N/C
11