Computational Thinking
By
Dept of CSE
PVPSIT, Kanuru.
PRASAD V. POTLURI SIDDHARTHA INSTITUTE OF TECHNOLOGY
Dept of CSE
2025-26
REVERSING THE DIGITS OF AN INTEGER
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
read (n)
reverse := 0;
while n > 0 do
begin
reverse := reverse * 10 + n mod 10;
n := n div 10
end;
dreverse := reverse
write out (dreverse)
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
Dept of CSE
2025-26
Supplementary problems
PVPSIT (Autonomous)
Problem Solving Techniques
(a) Use integer division to reduce the n value by a factor of 10.
(b) Increase the previous count by one.
4. Write out the number of digits in n i.e. stored in count.
Dept of CSE
2025-26
Solutions
PVPSIT (Autonomous)
Problem Solving Techniques
read (n)
count:= 0;
while n > 0 do
begin
n := floor (n div 10);
count := count + 1
end;
dcount:= count;
write out (dcount)
Dept of CSE
2025-26
Pseudo-code
PVPSIT (Autonomous)
Problem Solving Techniques
2.7.2 Design an algorithm to sum the digits in an integer.
(a) Use the remainder function to extract the rightmost digit of the number being summed.
(b) add the recently extracted rightmost digit to sum.
(c) use integer division by 10 to remove the rightmost digit from the number being summed.
4. Write out the sum.
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
read (n)
sum := 0;
while n > 0 do
begin
sum := sum + n mod 10;
n := n div 10
end;
dsum := sum;
write out (dsum)
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
2.7.3 Design an algorithm that reads in a set of n single digits and converts them into a single decimal integer. For example, the algorithm should convert the set of 5 digits {2, 7, 4, 9, 3} to the integer 27493.
(a) read next digit;
(b) increase the previous decimal integer value by multiplying with 10 and add the recently read digit;
(c) decrease number of numbers, n by one;
4. Write out the decimal integer.
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques
read (n)
dinteger := 0;
while n > 0 do
begin
read (digit);
dinteger := dinteger * 10 + digit;
n := n - 1
end;
write out (dinteger)
Dept of CSE
2025-26
PVPSIT (Autonomous)
Problem Solving Techniques