Greedy Algoritma
Greedy Algoritma
KELOMPOK 4
OLEH:
I PUTU AGRA ARIMBAWA (1929101032)
ANAK AGUNG DIAN WIDYA ASTUTI (1929101033)
AGUS CHANDRA ARYADI (1929101034)
I KETUT SUMANTRA (1929101035)
NYOMAN SUTRISNA JANUREKSA (1929101036)
I PUTU ASHADI SEDANA PRATAMA (1929101037)
LUH PUTU DIAH KUSUMADEWI 1929101038)
TAHUN
2019
7. A symmetric (5 x 5) Pascal matrix is displayed on the right. Write a
MATLAB program that creates an n x n symmetric Pascal matrix. Use
the program to create 4 x 4 and 7 x 7 Pascal matrices.
Source Code :
%{
Create a symmetric Pascal matrix n x n size.
n inputted by user.
Input : n
Output: matrix n x n
%}
Output Matrix 4 x 4
Output Matrix 7 x 7
Write a MATLAB program in a script file that determine 1t for any number of terms.
The program asks the user to enter the number of terms, and then calculates the
corresponding value of 1t. Execute the program with 5, 10, and 40 terms. Compare the
result with pi. (Use format long.)
Source Code :
%{
Create the approximation pi and compare the value with pi.
inputLength inputted by user.
Input : inputLength
Output: the approximation pi and compare value
%}
%{
Display approximate pi and display the difference value
between pi
and the approximation. Display as long format.
%}
fprintf('For input length = %d the approximation is
%1.10f.\n', n, piApprox);
fprintf('The difference between the pi and the approximation
is %1.10f.\n', abs(pi-piApprox));
end
Source Code :
24. Write a program that determines the change given back to a customer in a self-service
checkout machine of a supermarket for purchases of up to $50. The program generates
a random number between 0.01 and 50.00 and displays the number as the amount to
be paid. The program then asks the user to enter payment, which can be one $1 bill,
one $5 bill, one $10 bill, one $20 bill, or one $50 bill. If the payment is less than the
amount to be paid, an error message is displayed. If the payment is sufficient, the
program calculates the change and lists the bills and/or the coins that make up the
change, which has to be composed of the least number each of bills and coins. For
example, if the amount to be paid is $2.33 and a $10 bill is entered as payment, then
the change is one $5 bill, two $1 bills, two quarters, one dime, one nickel, and two
pennies. Execute the program three times.
Source Code :
%{
Generate random numbers with two decimal places between 0.01
until 50.00.
The generated number becomes the amount and users need to pay
by inputted pay amount.
Users will get the amount in words from the change.
Input : pay amount.
Output: amount in words.
%}