• Tidak ada hasil yang ditemukan

Fundamentals of Programming

N/A
N/A
Protected

Academic year: 2024

Membagikan "Fundamentals of Programming"

Copied!
35
0
0

Teks penuh

(1)

Lecture 4 Algorithms

and Flowcharts

(2)

Algorithms

(3)
(4)
(5)
(6)
(7)
(8)

END read N

p ← 1

p ← p * 2 N ← N - 1

N = 0

YES

NO

print p

(9)

END read N

p ← 1

p ← p * 2 N ← N - 1

N = 0

YES

NO print p

(10)

END read M, N

p ← 1

p ← p * 2 N ← N - 1

N = 0

YES

NO

print p

(11)

END read M, N

p ← 1

p ← p * M N ← N - 1

N = 0

YES

NO

print p

(12)

END read M, N

N ← N - M N < M

YES

NO

print N

(13)

END read M, N

R ← R - M R < M

YES

NO

print R R ← N

(14)

R ← R - M R < M

YES

NO

(15)

R ← R - M R < M

YES

NO R ← N

R

(16)

R ← R - M R < M

YES

NO R ← N

R

R ← N rem M

R ← N % M

(17)

END read N

k ← k + 1 k = N

YES

NO k ← 1

(18)

read N

k ← k + 1 k = N

NO k ← 2

N rem k = 0 NO

END

YES print

"prime"

END

YES print

"not prime"

(19)

read N

k ← k + 1 k > sqrt(N)

NO k ← 2

N rem k = 0 NO

END

YES print

"prime"

END

YES print

"not prime"

(20)

read N

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

END

YES print

"prime"

END

YES print

"not prime"

(21)

END read N

P ← random large integer

i ← P rem N

print i

(22)

END read N

P ← random large integer

i ← (P rem N) + 1

print i

(23)

END

P ← random large integer

i ← (P rem N) + 1

print i

N ← 37

(24)

Write an algorithm which takes a number

N and prints if it is prime or not

(25)

read N

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

END

YES print

"prime"

END

YES print

"not prime"

(26)

number N and prints it if N is prime

(27)

read N

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

END YES

print N

END YES

(28)

M and print all prime numbers up to M

(29)

read N

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

END YES

print N

END YES

(30)

read N

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

END YES

print N

END

Print N if prime

YES

(31)

read M

N ← N + 1 N > M

NO N ← 2

END YES

(32)

read M

N ← N + 1 N > M

NO N ← 2

END YES

Print N if prime

(33)

N ← N + 1 N > M

NO N ← 2

YES END

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

YES

print N

YES

(34)

N ← N + 1 N > M

NO N ← 2

YES END

k ← k + 1 k*k > N

NO k ← 2

N rem k = 0 NO

YES

print N

YES

nested loop!

(35)

i ← i + 1

i ≤ n

YES i ← 1

NO END

j ← j + 1

j ≤ i

YES j ← 1

NO

print j

Referensi

Dokumen terkait

It is not known if there are infinitely many Sophie Germain primes, and there do not appear to be any results of primes p where 2 p − 1 is also prime.. If anything is learned

Whenever you write anything online, sign it with your website address if you have one. This includes emails... A prime example of how this has worked for one company is hotmail. At

Since the objective function of (2) is not linear, no standard algorithm for solving linear or linear integer programming problems can be used to solve it. However,

1) Change the PrintIntArray subprogram so that it prints the array from the last element to the first element. Translate this pseudo code into MIPS assembly. This is a problem if

We will prove that these methods need a polynomial number of feasibility checks if all entries are integers and hence are also of pseudo-polynomial complexity.. The algorithm

Let’s try to create a bullet in the Game class, we can create it just after we make Fred, but do not add it to our vector of game objects until AFTER we make all the aliens,

Figure 4 showed the evolution of the coupling strength gn for which the synchronization of n neurons takes place according to the number n linearly coupled neurons incomplete

Write the negation of the statement • It is hot and the sun is shining • If the sun is shining then I will go to the beach • It is not raining • I will study or I will not pass