Computational Thinking - Counting
By
Dept. of CSE
PVPSIT, Kanuru.
PRASAD V. POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY
Dept. of CSE
2026
Algorithm 2.2
COUNTING
PVPSIT (Autonomous)
Problem Solving Techniques
55, 42, 77, 63, 29, 57, 89
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
While less than n marks have been examined do
(a) read next mark,
(b) if current mark satisfies pass requirement then add one to count.
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
read n
set passmark as 50
count := 0
i := 0
while i < n do
begin
i:= i+1
read m
if m >= passmark then count := count+1
end
writeout “no. of passes=”, count
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques
2.2.2 Design an algorithm that reads a list of numbers and makes a count of the number of negatives and the number of non-negative members in the set.
(a) read next number.
(b) if it is < 0 then add one to negative count
else add one to non-negative count.
4. Write out negative and non-negative counts.
Dept. of CSE
2026
Solution
PVPSIT (Autonomous)
Problem Solving Techniques
read (n)
negative_count := 0
non-negative_count := 0
total_count := 0
while total_count < n do
begin
read (number)
total_count := total_count+1
if number < 0 then
negative_count := negative_count+1
else
non-negative_count := non-negative_count+1
end
write out negative_count and non-negative_count
Dept. of CSE
2026
PVPSIT (Autonomous)
Problem Solving Techniques