Tampilkan postingan dengan label Fungsi IF ELSE. Tampilkan semua postingan
Tampilkan postingan dengan label Fungsi IF ELSE. 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

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

Sabtu, 29 September 2018

Latihan Soal Pemodelan Untuk Komputasi : Computational Thinking Ii

Latihan Soal Pemodelan untuk Komputasi : Computational Thinking II




Platform Length

A train passes a station platform in 36 seconds and a man standing on the platform in 20 seconds. If the speed of the train is 54 km/h, what is the length of the platform ? 



Train Passing

Train travelling at a speed of 8 km/h enters a tunnel 3 km long. The train is 1 km long. How long does it take for the train to pass through the tunnel from the moment the front enters to the moment the rear emerges? 



Man on a Box

A box having a length 3 m and breadth 2 m is floating on a lake. The box sinks by 0.01 m when a man gets on it. The density of the water of the lake is 1000 Kg/m3. What is the mass of the man?



Hello From Another Plane !!

Bob departed from Jakarta to Bandung at the same time as Alice departed from Bandung to Jakarta. The distance from Jakarta to Bandung is 170 km. If Bob’s average speed is 80 km/h and Alice’s average speed is 90 km/h. How long does it take for Bob and Alice to meet?



Speed Up

A car traveled from Jakarta to Padalarang in 5 hours. Then the car traveled back from Padalarang to Jakarta in 4 hours. If the distance between Jakarta and Padalarang is 160 km then how much speed increase did the car was needed to make on the second journey compared to the first journey? 



Coin Change

Every candy shop in Wombat Land always have 3 stacks of coins for change: W$100, W$50, and W$25. A customer came to one of the shop. She paid with W$500 coin for a W$325 worth candy bag. How many coins did she get as change? 




Magic Number #1

A two-digit number is such that the product of the digits is 8. When 18 is added to the number, then the digits are reversed. What number is it? 



Magic Number #2

The sum of the digits of a two-digit number is 15 and the difference between the digits is 3. What is the two-digit number?


The Chosen 4

In a group of 6 boys and 4 girls, four children are to be selected. In how many different ways can they be selected such that at least one boy should be there? 




More Water Please !

In a mixture 60 litres, the ratio of milk and water is 2 : 1. If this ratio is to be 1 : 2, then what is the quantity of water to be further added ? 














Sumber http://wikiwoh.blogspot.com