Looping Procees
Looping Procees
ALGORITHM
AND
FLOWCHART
Fundamentals of
Programming
By:
Erwin D. Marcelo
LOOPING Two types of loop process 2
Y
i<=N
N
Print End
sum
PRIME NUMBERS
Create an algorithm and a flowchart that determine if the
entered number is a PRIME or NOT
A prime number is a number that can only be divided by
itself and 1 without remainders.
ALGORITHM
X=B
1. Accept A, B
2. D = 1
3. If A < B then Y
A<B X=A
X=A
Else
N
X=B
4. While(D<= X) X=B
If (A mod D = 0 AND B mod D =
0)
GCD = D
D=D + 1 Amod d=0 Y
5. Print GCD GCD = D AND D<=X
B mod D=0
N
Print
D=D+1
GCD
END
FIBONACCI SERIES START
13 21 7 13 34 N
21 34 8 END
START
ALGORITHM
1. Accept N Read
2. a=0, b=1, ctr=0 N
3. DO
Print a a=0, b=1,
c=a+b ctr=0
a=b
b=c
ctr=ctr + 1 Print a
WHILE (ctr<N)
c= a +b, a=b,
b=c, ctr=ctr+1
Y
ctr<N
N
END
A B x1 x2 i ctr j Display i
PRIMES NUMBERS BETWEEN 2 GIVEN 5 2 2 5 2 0 1 2
NUMBERS 3 1 2 3
Create an algorithm and a flowchart that will output all the 4 2 3 5
prime numbers between 2 numbers. 5 0 1
Algorithm 6 1 2
2 3
1. Accept A, B
2. If A < B then 0 4
x1=A, x2 = B 1 1
Else 2 2
x1 = B, x2 = A
3. i = x1 3 3
4. WHILE (i <= x2) 0 4
ctr = 0 1 5
FOR j = 1 TO i
If ( i mod j =0) 2 1
ctr = ctr + 1 2
NEXT j 3
If ctr = 2 then
Display i 4
i=i+1 5
6
START