You are on page 1of 68

1

TUI1E3

PENGANTAR ALGORITMA

Fakultas Teknik Elektro


2

Components of an Algorithm
Values and Variables
Instruction (a.k.a. primitives)
Sequence (of instructions)
Procedure (involving instructions)
Selection (between instructions)
Repetition (of instructions)
Documentation (beside instructions)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


3

Sequence

A series of instructions
...to be carried out one after the other...
...without hesitation or question
Example:
How to cook a Gourmet Meal TM

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


4

Sequence--Example
1. Open freezer door
2. Take out Gourmet Meal™
3. Close freezer door
4. Open microwave door
5. Put Gourmet Meal™ on carousel
6. Shut microwave door
7. Set microwave on high for 5 minutes
8. Start microwave
9. Wait 5 minutes
10. Open microwave door
11. Remove Gourmet Meal™
12. Close microwave door

Deitel
4 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
5

Components of an Algorithm
Values and Variables
Instruction (a.k.a. primitives)
 Sequence (of instructions)
Procedure (involving instructions)
Selection (between instructions)
Repetition (of instructions)
Documentation (beside instructions)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


6

Procedure

A named sequence of instructions


So that you can
Refer to it collectively (by name)
...instead of individually (by each
instruction in the sequence)
Example:
Drive_To_Uni

Deitel
6 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
7

Procedure --Example
procedure Drive_To_Uni
{
1. find car keys
...etc...etc...etc...
2. disable car alarm
52. find parking space
3. open car door
53. pull into parking
4. get in car
space
5. shut car door
54. turn off engine
6. put keys in ignition
55. remove keys from
7. start car
ignition
8. back car out of
56. open car door
driveway
57. get out
9. drive to end of street
58. shut car door
10. turn right
59. lock car door
11. drive to end of street
60. enable alarm
12. turn left
}
...etc...etc...etc
Deitel
7 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
8

Procedure –Example (cont)


procedure Do_Wednesday procedure Do_Week
{ {
Wake_up Do_Monday
Do_Tuesday
Have_Shower Do_Wednesday
Eat_Breakfast Do_Thursday
Drive_To_Uni ...etc...etc...etc...
}
Sit_1301_Lecture
...etc...etc...etc...
Drive_From_Uni
...etc...etc...etc...
}

Deitel
8 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
9

Procedure –Example (cont)


procedure Do_Wednesday
{ In this subject, we also use
Wake_up the following words to
Have_Shower refer to a “Procedure” :
–Sub-routine
Eat_Breakfast
–Module
Drive_To_Uni –Function
Sit_1301_Lecture
...etc...etc...etc...
Drive_From_Uni
...etc...etc...etc...
}

Deitel
9 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
10

Procedure –Example (cont)

procedure Do_Wednesday
{
Wake_up
Have_Shower We use brackets to
Eat_Breakfast mark the
Drive_To_Uni beginning and end
Sit_1301_Lecture of a sequence.
...etc...etc...etc...
Drive_From_Uni
...etc...etc...etc...
}
Deitel
10 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
11

Procedure –Example (cont)


procedure Do_Wednesday
{
Wake_up
Have_Shower
Eat_Breakfast An instruction invoking a
Drive_To_Uni procedure is known as
Sit_1301_Lecture a “procedure call”
...etc...etc...etc...
Drive_From_Uni
...etc...etc...etc...
}

Deitel
11 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
12

Procedure
A procedure may have a set of parameters

procedure customerService ( myName ,timeOfDay )


{
say “Good timeOfDay”
say “My name is myName”
say “How can I help you?”
}

customerService ( “Ann”, “Morning” )


customerService (“Ann”, “Afternoon” )
customerService ( “Jeff”, “Afternoon” )
Deitel
12 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
13

Components of an Algorithm
Values and Variables
Instruction (a.k.a. primitives)
 Sequence (of instructions)
 Procedure (involving instructions)
Selection (between instructions)
Repetition (of instructions)
Documentation (beside instructions)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


14

Selection

An instruction that decides which of two


possible sequences is executed
The decision is based on a single true/false
condition
Examples:
• Car repair
• Reciprocals

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


15

Selection Example -- Car Repair


if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor
}
else
{
CheckDistributor
CheckIgnitionCoil
}
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
15
16
Selection Example –
Car Repair (cont)
if (motor turns)
then
{
CheckFuel
Should be a
CheckSparkPlugs true or false
CheckCarburettor condition.
}
else
{
CheckDistributor
CheckIgnitionCoil
}
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
16
17
Selection Example –
Car Repair (cont)
if (motor turns)
then
{
CheckFuel Sequence if
CheckSparkPlugs the condition
CheckCarburettor
is true.
}
else
{
CheckDistributor
CheckIgnitionCoil
}
17
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
18
Selection Example –
Car Repair (cont)
if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor
Sequence if the
}
condition is
else
false.
{
CheckDistributor
CheckIgnitionCoil
}
18
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
19

Selection Example -- Reciprocals

Examples:
Q. Give an
algorithm for Reciprocal of 2: 1/2
computing the
reciprocal of a
Reciprocal of -3/4:
number. 1/(-3/4) = -4/3
Reciprocal of 0:
“undefined”

19
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection Example – 20

Reciprocals (cont)
Algorithm:
input Num
if (Num is not equal 0)
Q. Give an then
algorithm for {
computing the output 1/Num
reciprocal of a }
number. else
{
output "infinity"
}

20
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection Example-- Reciprocals 21

Algorithm:
input Num
if (Num is not equal 0)
Num is a variable
whose value then
depends on the {
actual number the output 1/Num
user provides. }
else
{
output "infinity"
}
21
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection Example – 22

Reciprocals (cont)
Algorithm:
input Num
if (Num is not equal 0)
Condition then
depends on the {
value of Num output 1/Num
}
else
{
output "infinity"
}
22
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection Example – 23

Reciprocals (cont)
Algorithm:
input Num
if (Num is not equal 0)
then
{
For a given value of
output 1/Num
Num, only one of
these two sequences }
can be executed else
{
output "infinity"
}
23
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection Example – 24

Reciprocals (cont)
Algorithm:
input Num
if (Num is not equal 0)
then
{
Executed if Num is output 1/Num
not equal to 0 }
else
{
output "infinity"
}
24
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection Example – 25

Reciprocals (cont)
Algorithm:
input Num
if (Num is not equal 0)
then
{
output 1/Num
}
else
Executed if Num is {
equal to 0 output "infinity"
}
25
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
26
Selection -- Exercise
Will the following algorithms produce the same output?

Algorithm 1: Algorithm 2:
input Num input Num
if (Num is not equal 0) if (Num is not equal 0)
then then
{ {
output 1/Num output 1/Num
} }
else
{ output "infinity"
output "infinity"
}
26
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
27

Selection – Several Conditions


What if several conditions need to be satisfied?

if ( today is Wednesday and the time is 10.00am )


then
{
Go to CSE1301 Lecture
}
else
{
Go to Library
}

27
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Solution 1
28

Selection – Several Conditions (cont)

if ( today is Wednesday )
then Often called a
{
if ( the time is 10.00am ) “nested selection”
then
{
Go to CSE1301 Lecture
}
}
else
...etc...etc...etc...
Solution 2
28
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
29

Selection – At Least One of Several


Conditions
What if at least one of several conditions needs to be
satisfied?
if ( I feel hungry or the time is 1.00pm or my
mate has his eye on my lunch )
then
{
Eat my lunch now
}

29
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 30

Several Courses of Action


What if there are several courses of action?
if ( button pressed is 1 ) {
then PayBills
{ }
CheckAccountBalance else
} {
else if ( button pressed is 4 )
{ then
if ( button pressed is 2 ) {
then ExitPhoneBanking
{ }
TransferFunds else
} {
else say “Invalid option”
{ }
if ( button pressed is 3 ) }
then }
}
Form 1
30
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 31

Several Courses of Action (cont)


if ( button pressed is 1 ) {
then PayBills
{ }
CheckAccountBalance else
} {
else if ( button pressed is 4 )
{ then
if ( button pressed is 2 ) {
then ExitPhoneBanking
{ }
TransferFunds else
} {
else say “Invalid option”
{ }
if ( button pressed is 3 ) }
then } Form 1
}
31
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
One
condition per Selection – 32

Several Courses of Action (cont)


course of
action

if ( button pressed is 1 ) {
then PayBills
{ }
CheckAccountBalance else
} {
else if ( button pressed is 4 )
{ then
if ( button pressed is 2 ) {
then ExitPhoneBanking
{ }
TransferFunds else
} {
else say “Invalid option”
{ }
if ( button pressed is 3 ) }
then } Form 1
}
32
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 33

Several Courses of Action (cont)


{
if ( button pressed is 1 ) PayBills
then }
{ else
CheckAccountBalance {
} if ( button pressed is 4 )
else then
{ {
if ( button pressed is 2 ) ExitPhoneBanking
then }
{ else
TransferFunds {
} say “Invalid option”
else }
{ }
if ( button pressed is 3 ) }
then }

33
Form 1
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 34

Several Courses of Action (cont)


{
if ( button pressed is 1 ) PayBills
then }
{ else
CheckAccountBalance {
} if ( button pressed is 4 )
else then
{ {
if ( button pressed is 2 ) ExitPhoneBanking
then }
{ else
TransferFunds {
} say “Invalid option”
else }
{ }
if ( button pressed is 3 ) }

Form 1
then }

34
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 35

Several Courses of Action (cont)


{
if ( button pressed is 1 )
PayBills
then
}
{
else
CheckAccountBalance
{
}
if ( button pressed is 4 )
else
then
{
{
if ( button pressed is 2 )
ExitPhoneBanking
then
}
{
else
TransferFunds
{
}
say “Invalid option”
else
}
{
}
if ( button pressed is 3 )
}
then
}
35
Form 1
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 36

Several Courses of Action (cont)


if ( button pressed is 1 ) {
then PayBills
{ }
CheckAccountBalance else
} {
else if ( button pressed is 4 )
{ then
if ( button pressed is 2 ) {
then ExitPhoneBanking
{ }
else “Default” sequence
TransferFunds
} { (may be optional)
else say “Invalid option”
{ }
if ( button pressed is 3 ) }
then }
} Form 1
36
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 37

Several Courses of Action (cont)


if ( button pressed is 1 ) else if ( button pressed is 4 )
then then
{ {
CheckAccountBalance ExitPhoneBanking
} }
else if ( button pressed is 2 ) else
then {
{ say “Invalid option”
TransferFunds }
}
else if ( button pressed is 3 )
then
Form 2
“Cascaded”
{
PayBills selection.
}

37
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
Selection – 38

Several Courses of Action (cont)


if ( button pressed is 1 ) else if ( button pressed is 4 )
then then
{ {
CheckAccountBalance ExitPhoneBanking
} } Optional default
else if ( button pressed is 2 ) else sequence.
then {
{ say “Invalid option”
TransferFunds }
}
else if ( button pressed is 3 )
Form 2
then
{
PayBills
}

38
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
39

Components of an Algorithm
Values and Variables
Instruction (a.k.a. primitives)
 Sequence (of instructions)
 Procedure (involving instructions)
 Selection (between instructions)
Repetition (of instructions)
Documentation (beside instructions)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


40

Repetition

• Repeat an instruction...
• ...while (or maybe until) some true or false condition
occurs
• Test the condition each time before repeating the
instruction

• Also known as iteration or loop


• Example:
• Algorithm for getting a date

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


41

Repetition -- Example
procedure AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
add 1 to begging count
ListenToReply ( )
}
}
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
41
42

Repetition – Example (cont)


procedure AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while ( reply is "No" and begging count < 100 )
{
Say("Oh please!")
add 1 to begging count Condition is tested
ListenToReply ( ) before sequence
}
}

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


42
43

Repetition – Example (cont)

procedure AskOnDate ( name, time, location )


{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!") Sequence may not
add 1 to begging count
get executed at all
ListenToReply ( )
}
}
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
43
44

Repetition – Example (cont)


procedure AskOnDate ( name, time, location ) Ensure initial values of
{ variables used in the
Phone(name) conditions are set correctly
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
add 1 to begging count
ListenToReply ( )
}
}

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


44
45

Repetition – Example (cont)


procedure AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!") Ensure the variables
add 1 to begging count used in the conditions
ListenToReply ( )
are updated in each
}
iteration
}

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


45
46

Repetition – Example (cont)


• What if we don’t increment the begging count?
procedure AskOnDate ( name, time, location )
{
Phone(name)
Say("Hey", name, "it's your lucky day!")
Say("Wanna come to", location, "at", time, "?")
ListenToReply ( )
start begging count at zero
while (reply is "No" and begging count < 100)
{
Say("Oh please!")
} Infinite loop
}
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
46
47

Repetition – Variation
decide on Time and Location
initialise booking to “unsuccessful”
while ( not successfully booked )
{
get next Name in little black book
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
}
SighWithRelief

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


47
48

Repetition – Pre-Tested Loop

decide on Time and Location


initialise booking to “unsuccessful”
while ( not successfully booked )
{
pre-tested loop
get next Name in little black book
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
}
SighWithRelief

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


48
49

Repetition – Pre-Tested Loop

decide on Time and Location


initialise booking to “unsuccessful”
until ( successfully booked )
{ pre-tested loop
get next Name in little black book
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
}
SighWithRelief

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


49
50

Repetition – Post-Tested
Loop
decide on Time and Location
initialise booking to “unsuccessful”
do Sequence is
{ executed at
get next Name in little black book
least once
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
} while ( not successfully booked )

post-tested loop
SighWithRelief

Deitel
50 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
51

Repetition – Post-Tested Loop


decide on Time and Location
initialise booking to “unsuccessful”
repeat
{
get next Name in little black book
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
} until ( successfully booked )

SighWithRelief

Deitel
51 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
52

Repetition – Variations
decide on Time and Location
initialise booking to “unsuccessful”
loop
{
get next Name in little black book
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
if ( successfully booked )
then
{
break loop
}
}
SighWithRelief

Deitel
52 & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
53

Components of an Algorithm
Values and Variables
Instruction (a.k.a. primitives)
 Sequence (of instructions)
 Procedure (involving instructions)
 Selection (between instructions)
 Repetition (of instructions)
Documentation (beside instructions)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


54

Documentation
Records what the algorithm does
Describes how it does it
Explains the purpose of each component of
the algorithm
Notes restrictions or expectations
Example:
Getting a date (again)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


55

Documentation
Think of something romantic to do
decide on time and location

Work through address book to look for a person


initialise booking to “unsuccessful”
until (successfully booked)
{
get next Name in little black book
AskOnDate(Name, Time, Location)
DetermineBookingSuccess
}

Assumes that I will find someone in the book before it runs out
SighWithRelief
Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13
55
56

Components of an Algorithm
Values and Variables
Instruction (a.k.a. primitives)
 Sequence (of instructions)
 Procedure (involving instructions)
 Selection (between instructions)
 Repetition (of instructions)
 Documentation (beside instructions)

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


57

Software Development
Process
Define the problem clearly
Analyse the problem thoroughly
Design an algorithm carefully
Code the algorithm efficiently
Test the code thoroughly
Document the system lucidly

Deitel & Deitel, C: How to program Chapter 3, Sections 3.8 to 3.13


58

STRUKTUR PEMILIHAN
Struktur Pemilihan adalah suatu statement untuk
pengambilan keputusan berdasarkan kondisi
tertentu.
IF
If
If else
If, else if, else
Switch Case
59

IF
Bentuk If adalah yang paling sederhana,
mengandung suatu pernyataan tunggal yang
dieksekusi jika ekspresi bersyarat adalah benar.
Sintaks dasar:
60

IF
Proses penyeleksian berdasarkan kondisi relasi
tertentu.
Bentuk if Tunggal

Jika kondisi benar, maka instruksi akan dijalankan.


61

IF,ELSE
Untuk melakukan beberapa operasi yang berbeda
jika salah satu ekspresi kondisional bernilai salah,
maka digunakan statement else. Bentuk if-else
memungkinkan dua alternatif operasi pemrosesan.
Sintaks dasar:
62

Bentuk if, else

Jika kondisi benar, maka instruksi akan dijalankan.


Bila salah, maka instruksi pada else yang akan
dijalankan.
63

IF,ELSE IF, ELSE


Bentuk if, else if, else memungkinkan untuk tiga atau
lebih alternative pemrosesan.
Sintaks dasar:
64

Jika kondisi benar, maka instruksi akan dijalankan.


Bila salah, makaakan melihat kondisi pada else if.
Jika benar, maka instruksi pada else if yang akan
dijalankan. Bila salah juga, maka instruksi pada else
yang akan dijalankan.
65

CONTOH
66

SWITCH
Switch adalah pernyataan yang digunakan untuk
menjalankann salah satu pernyataan dari beberapa
kemungkinan statement untuk dieksekusi,
berdasarkan nilai dari sebuah ungkapan dan nilai
penyeleksi. Setiap ungkapan diungkapkan dengan
sebuah nilai integral konstan, seperti sebuah nilai
dengan tipe byte, short, int atau char.
67

SWITCH
Proses penyeleksian berdasarkan kondisi nilai suatu variabel.
Instruksi yang dijalankan sesuai
dengan nilai pada case yang telah
ditentukan. Apabila tidak ada, maka
intruksi pada default yang akan
dijallankan.
68

#include<stdio.h> case 3: // Bila nilainya 3


Int main() printf(“Masukkan bilangan pertama : “); scanf(“%f”,&satu);
{ printf(“Masukkan bilangan kedua : “); scanf(“%f”,&dua);
int pilih; hasil= satu * dua;
float satu,dua,hasil; printf(“Hasil perkalian = %10.3f“, hasil);
printf(“Program Kalkulator sederhana \n”); break;
printf(“Menu : \n”); case 4: // Bila nilainya 4
printf(“1. Penjumlahan \n”); printf(“Masukkan bilangan pertama : “); scanf(“%f”,&satu);
printf(“2. Pengurangan \n”); printf(“Masukkan bilangan kedua : “); scanf(“%f”,&dua);
printf(“3. Perkalian \n”); hasil = satu / dua;
printf(“4. Pembagian \n”); printf(“Hasil pembagian = %10.3f“, hasil);
printf (“Pilih (1-4): “); scanf(“%d”,&pilih); break;
clrscr(); // Membersihkan layar default: // Bila nilainya tidak termasuk di
switch (pilih) { dalam case-case di atas
case 1 : // Bila nilainya 1 printf(“Tidak ada di dalam menu“);
printf(“Masukkan bilangan pertama : “); scanf(“%f”,&satu); break;
printf(“Masukkan bilangan kedua : “); scanf(“%f”,&dua); }
hasil= satu + dua; printf(“\nTerima kasih telah menggunakan program ini”);
printf(“Hasil penjumlahan = %10.3f“, hasil); return 0;
break; }
case 2 : // Bila nilainya 2
printf(“Masukkan bilangan pertama : “); scanf(“%f”,&satu);
printf(“Masukkan bilangan kedua : “); scanf(“%f”,&dua);
hasil= satu - dua;
printf(“Hasil pengurangan = %10.3f“, hasil);
break;
68

You might also like