Tampilkan postingan dengan label Komputasi. Tampilkan semua postingan
Tampilkan postingan dengan label Komputasi. Tampilkan semua postingan

Senin, 01 Oktober 2018

Latihan Soal Pemodelan Untuk Komputasi : Repetition Atau Pengulangan

Latihan Soal Pemodelan untuk Komputasi : Repetition atau Pengulangan


Latihan Soal


Kelipatan 3

Buatlah algoritma untuk menampilkan n (n>=1) buah kelipatan 3 yang pertama!


Faktor 

Buatlah algoritma untuk menampilan semua faktor dari bilangan bundar x! Faktor-faktor ini harus ditampilkan dari yang terbesar hingga yang terkecil!

State


  • Perhatikanlah flowchart di bawah ini! Tentukanlah berapa saja nilai r hingga alhasil loops berakhir! 



  • Permasalahan apa yang diselesaikan oleh flowchart tersebut? Coba jalankan flowchart tersebut untuk n = 20 dan m = 30


Faktorial

Buatlah flowchart untuk menghitung nilai dari n faktorial (n!)!

Bunga Tabungan

Jika diketahui bunga beragam pertahun yaitu n persen, dan tabungan awal yaitu y, di tahun ke-berapakah tabungan menjadi 2y? Buatlah flowchart-nya dengan memakai loop!

Fibonacci

Buatlah algoritma untuk mencari bilangan Fibonacci ke-i. Bilangan Fibonacci ke-1 yaitu 0, Bilangan Fibonacci ke-2 yaitu 1, dan untuk setiap bilangan Fibonacci ke-i (i>2), Bilangan Fibonacci ke-i diperoleh dengan menjumlahkan Bilangan Fibonacci ke-(i-1) dengan Bilangan Fibonacci ke-(i-2). Berikut ini yaitu deret Fibonacci: 0, 1, 1, 2, 3, 5, 8, …

Jawaban Latihan Soal

Kelipatan 3


Faktor




Faktorial



Atau


Bunga Tabungan




Fibonacci




Sumber http://wikiwoh.blogspot.com

Pemodelan Untuk Komputasi : Logical Operator & Selection Dan Referensi Soal ( Bahasa Inggris )

Pemodelan untuk Komputasi : Logical Operator & Selection dan Contoh Soal ( Bahasa Inggris )




Introduction of Logic Operator & Selection

The university bookstore has a Kilobyte Day sale every October 24, giving an 8 percent discount on all computer accessory purchases if the price is less than $128, and a 16 percent discount if the price is at least $128. Write a agenda that asks the cashier for the original price and then prints the discounted price.


Solution
  • Check whether a condition is true or false à Is the price less than $128? (the answer is true or false).
  • Select only an alternative to be done and ignore any other alternative(s)



Relational Operator & Expressions


In order to make a decision, we need to know a condition that makes an alternative is chosen. In many cases, the condition involves comparing values. To compare values, we need :
  • Relational operator : an operator that is used to tests the relationship between two values.
  • Relational expressions : expression using relational/logical operator, the result of this expression is true or false



Relational Operator


Example

  • price < 128 (price is less than 128)
  • price >= 128 (price is greater than 128)
  • price = 128 (price equals to 128)
  • price ≠ 128 (price does not equal to 128)


Relational Expression

  • Relational expressions : expression using relational/logical operator, the result of this expression is true or false
  • Logical operator (AND, OR, NOT)
  • Example: the price <= 128 AND today = SUNDAY





Algorithms of Relational Expression



Use IF statement in our algorithm if it needs to choose between some different steps/alternatives. After the IF statement, we also need to write the conditions that are needed to be checked.

IF (conditions) then steps

The conditions are written using the relational expression. Example:

IF(price <=128) then discount = 0.08 * price

To choose an alternative, algorithm can have a compound conditions. Use the logical operator to make compound conditions. Example:

IF nilai >70 AND nilai <80 then nilaiHuruf = B





IF – ELSE

  • IF-ELSE statement chooses between two alternatives.
    • IF (conditions) then steps
    • ELSE steps
  • Example :
    • IF (nilaiHuruf=E) then status = tidak lulus
    • ELSE status = lulus


Example




Flowchart of Relational Expression

We use the diamond to symbolize the selection in flowchart. The diamond will have some branches. We can add the condition inside the diamond.

E.g. price<=128



Examples


Vowel or Consonant

Write the algorithms and draw the flowchart to check if a letter is a vowel or a consonant.





MAX

Write the algorithms and draw the flowchart to find maximum between two numbers






Exercise 1


Relational Operator



Some operators checks about the relationship between two values and these operators are called relational operators. Given two numerical values your job is just to find out the relationship between them that is (i) First one is greater than the second (ii) First one is less than the second.


Triangle



A long time ago, the Egyptians figured out that a triangle with sides of length 3, 4, and 5 had a right angle as its largest angle. Given the length of the sides of triangle, you must determine if the triangles have a similar property. The given lengths are always increasingly ordered.


Distance



Two wombats stand on a position in cartesian system of coordinates. Based on their position, we can determine if they are close friends or not. We can say that two wombats are close friends if their distance is less than or equals 200. Write the algorithms and the flowchart to determine if two wombats are close friends.


The Queen Problem


Given the positions (row and col number) of two queens on a chessboard. Your job is to write the algorithm and draw the flowchart to check if the two queens can attack each other.

Sumber http://wikiwoh.blogspot.com

Minggu, 30 September 2018

Matematika Diskrit : Operasi Pada Himpunan Dan Teladan Soal

Matematika Diskrit : Operasi pada Himpunan dan Contoh Soal



Irisan (intersection)





Irisan dari himpunan A dan B yaitu suatu himpunan yang setiap anggotanya yaitu anggota himpunan A dan B. 

Notasi :



Contoh : 

A = {1,5,7,9} 
B = {1,2,3} 

maka



Gabungan (union





Gabungan himpunan A dan B yaitu himpunan yang setiap anggota yaitu anggota himpunan A atau B 

Notasi : 


Contoh:


A = {1,2} dan B = {2,5,6}



Komplemen 





Komplemen dari suatu himpunan A terhadap suatu semesta U yaitu suatu himpunan yang anggotanya merupakan anggota U yang bukan anggota A 

Notasi : 




Contoh : 

Misalkan U = {1,2,3,…,10}. Jika A = {1,4,5}, maka 





Selisih (difference)



Selisih dua himpunan A dan B yaitu himpunan yang anggotanya merupakan anggota dari A namun bukan anggota dari B. 

Notasi :




Contoh :

A = {1,2,…,10} dan B = {1,2,3,11}
maka A-B = {4,5,…,10}


Beda setangkup (symmetric difference)

Beda setangkup dari himpunan A dan B yaitu suatu himpunan yang anggotanya ada pada himpunan A atau B tapi tidak pada keduanya.

Notasi :




Contoh : 

A = {1,2,3} dan B = {3,5,6}, maka hasilnya





Teorema Beda Setangkup (berkaitan dengan beda setangkup) 

( aturan komutatif ) 



( aturan asosiatif )




Perkalian Kartesian (cartesian product)

Perkalian kartesian dari himpunan A dan B yaitu himpunan yang anggotanya semua pasangan berurut yang dibuat dari komponen dari A dan komponen dari B

Notasi :





Contoh :

A = {1,2,3} dan B = {a,b}
maka A x B = {(1,a), (1,b), (2,a), (2,b), (3,a), (3,b)}


Catatan (berkaitan dengan perkalian kartesian):

Jika A dan B merupakan himpunan berhingga, maka |A x B| = |A||B|

(a,b)  (b,a)









Latihan 1


1. Jika A = {1,2}, B = {x,y,z}, dan C = {3,4}. Tentukan |A x B x C| dan A x B x C. 

2. Misalkan 
  • A = himpunan semua buah berwarna merah 
  • B = himpunan semua buah yang diimpor 
  • E = himpunan semua buah yang dijual di Toko X 
Notasikan : 

Himpunan buah di Toko X yang berwarna merah atau yang diimpor 


Latihan 2






Sumber http://wikiwoh.blogspot.com

Pemodelan Untuk Komputasi : Selection Ii, Nested-If, Multiway-If, Dan Pola Soal ( Bahasa Inggris )

Pemodelan untuk Komputasi : Selection II, Nested-IF, Multi-IF, dan Contoh Soal ( Bahasa Inggris )






Introduction of Selection II



The Richter scale is a measurement of the strength of an earthquake. Every step in the scale, for example from 6.0 to 7.0, signifies a tenfold increase in the strength of the quake. We can categorize the scale into 5 categories: Category A (most structures fall), B (many buildings destroyed), C (many buildings considerably damaged, some collapse), D (damage to poorly constructed buildings), and E (no destruction of buildings). Write the kegiatan to categorize the Ritcher scale!



Notes :

  • Is it enough to use only if-else structure to solve the previous problem?
  • We need more than one alternative to categorize the Ritcher scale.
  • Solution: use multiway if-else or nested if


Algorithms of Multiway IF – ELSE 


We can use multi-way IF – ELSE if there are several alternatives that are needed to be chosen by our algorithm. 

IF (conditions) then steps 
ELSE-IF (conditions) then steps 
… 
… 
... 
ELSE stepsFlowchart: Multiway IF – ELSE 

Flowchart of Multiway IF – ELSE




Multiway IF – ELSE Example



Algoritmic Table



Flowchart






Nested IF

Nested IF is an if statement inside another. Any masalah that involves a multiway IF – ELSE can be solved using Nested IF. Furthermore, there are no differences between multiway IF – ELSE and Nested IF

Nested IF Example



Examples

Tax Regulation

Write an algorithm and draw the flowchart to calculate the income tax based on this regulation!



Algorithm: Tax Regulation



Exercise 1


Salary

You are given the salaries of these 3 employees working in the accounts department. You have to find out the minimum salary of those employees. Write the algorithms and draw the flowchart!



The Colors

In RYB colors, there are three primary colors: red, blue, and yellow. We can make a secondary color by mixing up two primary colors. We can create green by mixing up the blue and the yellow. The orange is created by mixing up red and yellow. The purple is created by mixing up red and blue. 

Given two primary colors, make an algorithm to find out what is the secondary color created by those primary colors !




Leap Year

Write an algorithm and draw the flowchart to determine if a year is a leap year. A leap year is a calendar day containing one additional day. These extra days occur in years which are multiples of four (with the exception of years divisible by 100 but not by 400).





Zapping

My TV remote is almost broken. Only △ and ▽ are working. My TV has 100 channels conveniently numbered 0 through 99. They are cyclic, in the sense that if I’m on channel 99 and press △ I’ll go to channel 0. Similarly, if I’m on channel 0 and press ▽ I’ll change to channel 99. I would like a kegiatan that, given the channel I’m currently watching and the channel I would like to change to, tells me the minimum number of button presses I need to reach that channel. 

Write the algorithm and draw the flowchart!



How Old Are You

Given two dates: current date and a birth date of a person. Write your algorithm and draw the flowchart to calculate how old a person is! Assume that there are no invalid date (current date is < birth date). 

Example: 
  • Current Date: 12/11/2007 
  • Birth Date: 01/01/1984 
  • Age: 23


Chocolate Bar



We want to make a package of goal kilos of chocolate. We have small bars (1 kilo each) and big bars (5 kilos each). Count the number of small bars to use, assuming we always use big bars before small bars. Output -1 if it can't be done. 

Example : 



Sumber http://wikiwoh.blogspot.com