You are on page 1of 6

1.

Rancang Program komputer untuk menentukan nilai P dari rumusan berikut, jika nilai a,b,c,
𝑐 𝑎
dan d diketahui : 𝑃 = 𝑏 2 + 𝑏+𝑑 + 𝑑
Jawaban:

Masalah nya :

c a
 Determine the value of P from the formula P  b 2  
bd d
 Input koef : a, b, c,d
 Output : value of P

1) Data Structure
Unit Variable Type of Data Description
Coefficient a a Real/Numeric Input data
Coefficient b b Real/Numeric Input data
Coefficient c c Real/Numeric Input data
Coefficient d d Real/Numeric Input data
Value of P P Real/Numeric Output data

2) Algorithm Program
a. Start
b. Input data
Input a
Input b
Input c
c. Process
x  b+d;
if x~=0 then
P  b^2+(c/x)+(a/d);
else x==0
P  b^2+(c/x)+(a/d);
end
d. 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
e. Stop

3) Coding in MatLab

%data input
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=b^2+(c/x)+(a/d);
else x=0
P=b^2+(c/x)+(a/d);
end
%Output
if x~=0
disp('The value of P is definite');
fprintf('P =%5.2f \n',P);
else x=0
disp('The value of P is infinite');
fprintf('P =%5.2f \n',P);
end

4) Program Pengujian
a) Coef a= 8
Coef b= -20
Coef c= 20
Coef d= 20
x=0
Nilai P tidak terbatas
P = Inf

b) Coef a= 3
Coef b= 17
Coef c= 5
Coef d= 6
Nilai P pasti
P =290,0555

2. Rancang Program komputer untuk menentukan nilai P dari rumusan berikut, jika nilai a,b,c,
dan d diketahui : 𝑃 = 𝑎 + 𝑏 2 + √𝑐 − 𝑑
Jawaban :

Problem Definition

 Determine the value of P from the formula P  a  b 2  c  d


 Input koef : a, b, c,d
 Output : value of P

1) Data Structure
Unit Variable Type of Data Description
Coefficient a a Real/Numeric Input data
Coefficient b b Real/Numeric Input data
Coefficient c c Real/Numeric Input data
Coefficient d d Real/Numeric Input data
Value of P P Real/Numeric Output data

2) 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(x);
Elseif x=0
P  a+b^2+ sqrt(x);
else
P  a+b^2+ sqrt(x);
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
write('The value of P is infinite');
write(P);
end if
e. Stop

3) 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(x);
elseif x==0
P=a+b^2+ sqrt(x);
else
Pc=a+b^2+ sqrt(x);
end
%Output
if x>0
disp('The value of P is definite');
fprintf('P =%5.2f \n',P);
elseif x==0
disp('The value of P is definite');
fprintf('P =%5.2f \n',P);
else
disp('The value of P is complex');
fprintf('P =%5.2f \n',P);disp(Pc);
end
4) Program Pengujian
a) Coef a= 2
Coef b= 4
Coef c= 9
Coef d= 8
Nilai P pasti
P = 18.00

b) Coef a= 1
Coef b= 7
Coef c= 10
Coef d= 12
Nilai P adalah kompleks
P =50.00
50.0000 + 1.4142i

c) Coef a= 9
Coef b= 3
Coef c= 5
Coef d= 4
Nilai P pasti
P =18.00

You might also like