You are on page 1of 22

Structur and development in

C
Struktur Data
Algorithms
1. the actions to be executed.
2. the order in which these actions are to be executed
Pseudocode
• Pseudocode is an artificial and informal language that helps you
develop algorithms.
• present the particularly useful for developing algorithms that will be
converted to structured C programs.
• Pseudocode is similar to everyday English; it’s convenient and user
friendly although it’s not an actual computer programming language.
• Pseudocode programs are not executed on computers.
• help you “think out” a program before attempting to write it in a
programming language such as C
Flowchart
• is a graphical representation of an algorithm or of a portion of an
algorithm.
• Flowcharts are drawn using certain special-purpose symbols such as
rectangles, diamonds, ovals, and small circles; these symbols are
connected by arrows called flowlines.
• Like pseudocode, flowcharts are useful for developing and
representing algorithms, although pseudocode is preferred by most
programmers.
Flowchart Symbol
Input/
Terminator Process
output

Off
Connector Page
Manual Input
Connector

Etc. ……..
Start

Bayar,
jmlBarang,
hrgSatuan

Model Flowchart 1
jmlBarang,
hrgSatuan

jmlBarang Ya Bayar=10% x hrgSatuan x


> 50 jmlBarang

Tidak

Bayar=hrgSatuan x
Finish
jmlBarang
Start B A

Bayar,
jmlBarang, Bayar=hrgSatuan x Bayar=10% x hrgSatuan x
hrgSatuan jmlBarang jmlBarang

jmlBarang,
hrgSatuan Finish

jmlBarang Ya A
> 50

Tidak Model Flowchart 2


B
Start A
B

Bayar,
jmlBarang, Bayar=10% x hrgSatuan x
hrgSatuan jmlBarang Bayar=hrgSatuan x
jmlBarang
C
jmlBarang,
hrgSatuan C

Finish
jmlBarang Ya A
> 50

Tidak

B
Halaman 1 Halaman 2

Model Flowchart 3
Bayar, jmlBarang , hrgSatuan : integer
hrgSatuan  500
Read (jmlBarang);
if jmlBarang > 50 than
Bayar  10% *hrgSatuan * jmlBarang
else
Bayar  hrgSatuan *jmlBarang
end if
Print (“Yang harus dibayar ”, Bayar)
end
Out-put
Other Ways

• Nested if…else statements test for multiple cases by placing if…else


statements inside if…else statements
Ex
Set total to zero
Set grade counter to one
While grade counter is less than or equal to ten
Input the next grade
Add the grade into the total
Add one to the grade counter
Set the class average to the total divided by ten
Print the class averag
counter, grade, total, average : integer
total 0
counter 1
While counter<=10
print(“Enter grade”)
Read(grade)
Totaltotal+grade
countercounter+1
End while
average total/10
Print (“average”,average)
End
Translate into C
Output
Decision Making: Equality and Relational
Operators
Algebraic equality or C equality or Example of Meaning of C
relational operator relational operator C conditions conditions
Equality operators
= == x == y x is equal to y
≠ != x != y x is not equal to y
Relational operators
> > x>y x is greater than y
< < x<y x is less than y
≥ >= x >= y x is greater than or equal
to y
≤ <= x <= y x is less than or equal to y
Assign Operator
Assignment Sample Explanation Assigns
operator expression

Assume: int c = 3, d = 5, e = 4, f = 6, g = 12;

+= c += 7 c=c+7 10 to c
-= d -= 4 d=d–4 1 to d
*= e *= 5 e=e*5 20 to e
/= f /= 3 f=f/3 2 to f
%= g %= 9 g=g%9 3 to g
Increment and Decrement Operators
Operator Sample Explanation
expression
++ ++a Increment a by 1, then use the new value of a in
the expression in which a resides.
++ a++ Use the current value of a in the expression in
which a resides, then increment a by 1.
-- --b Decrement b by 1, then use the new value of b
in the expression in which b resides.
-- b-- Use the current value of b in the expression in
which b resides, then decrement b by 1
#include <stdio.h>
int main( void )
{
int c;
c = 5;
printf( "%d\n", c );
printf( "%d\n", c++ );
printf( "%d\n\n", c );
c = 5;
printf( "%d\n", c );
printf( "%d\n", ++c );
return 0;
}
Thank You
References
• Deitel., P. dan Deitel., H., “C How To Program Sixth Edition”, 2010 , Pearson Education, Inc.
Upper Saddle River, New Jersey 0745

You might also like