Learn ICT Faster and Better
Theory, Programming Exercises, Past Paper Questions and Answers, Assignments with Answers Practical Videos Learn ICT By Examples
Tuesday, January 6, 2026
Exercises to Learn Algorithm and Programming| Every Programmer should try
Problem 1
Write an algorithm to read two numbers and print their sum.
Algorithm (Pseudocode>
Start
Read A, B
SUM ← A + B
Print SUM
Stop
Pascal Program
program SumOfTwoNumbers;
var
A, B, SUM: integer;
begin
writeln('Enter value of A: ');
readln(A);
writeln('Enter value of B: ');
readln(B);
SUM := A + B;
writeln('Sum = ', SUM);
end.
Python Program
# Read two numbers
A = int(input("Enter value of A: "))
B = int(input("Enter value of B: "))
# Calculate sum
SUM = A + B
# Print result
print("Sum =", SUM)
Problem 2
Write an algorithm to find the larger of two numbers.
Algorithm Pseudocode
Start
Read A, B
If A > B
Print A
Else
Print B
Stop
Pascal Program
program FindGreaterNumber;
var
A, B : integer;
begin
readln(A, B);
if A > B then
writeln(A)
else
writeln(B);
end.
Python Program
A = int(input())
B = int(input())
if A > B:
print(A)
else:
print(B)
Problem 3
Write an algorithm to check whether a number is even or odd
Algorithm Pseudocode
Start
Read N
If N mod 2 = 0
Print "Even"
Else
Print "Odd"
Stop
Pascal Program
program EvenOdd;
var
N: integer;
begin
writeln('Enter a number: ');
readln(N);
if N mod 2 = 0 then
writeln('Even')
else
writeln('Odd');
end.
Python Program
N = int(input("Enter a number: "))
if N % 2 == 0:
print("Even")
else:
print("Odd")
Problem 4
Write an algorithm to calculate simple interest.
Formula:
SI = (P × R × T) / 100
Algorithm Pseudocode
Start
Read P, R, T
SI ← (P × R × T) / 100
Print SI
Stop
Pascal Program
program SimpleInterest;
var
P, R, T, SI: real;
begin
writeln('Enter Principal (P): ');
readln(P);
writeln('Enter Rate (R): ');
readln(R);
writeln('Enter Time (T): ');
readln(T);
SI := (P * R * T) / 100;
writeln('Simple Interest = ', SI:8:2);
end.
Python Program
P = float(input("Enter Principal (P): "))
R = float(input("Enter Rate (R): "))
T = float(input("Enter Time (T): "))
SI = (P * R * T) / 100
print("Simple Interest =", SI)
Problem 5
Write an algorithm to reverse a number.
Algorithm Pseudocode
Start
Read N
REV ← 0
While N > 0
DIGIT ← N mod 10
REV ← REV × 10 + DIGIT
N ← N / 10
EndWhile
Print REV
Stop
Pascal Program
program ReverseNumber;
var
N, REV, DIGIT: integer;
begin
writeln('Enter a number: ');
readln(N);
REV := 0;
while N > 0 do
begin
DIGIT := N mod 10;
REV := REV * 10 + DIGIT;
N := N div 10;
end;
writeln('Reversed Number = ', REV);
end.
Python Program
N = int(input("Enter a number: "))
REV = 0
while N > 0:
DIGIT = N % 10
REV = REV * 10 + DIGIT
N = N // 10
print("Reversed Number =", REV)
Problem 6
Write an algorithm to check whether a number is a palindrome.
Algorithm Pseudocode
Start
Read N
TEMP ← N
REV ← 0
While TEMP > 0
DIGIT ← TEMP mod 10
REV ← REV × 10 + DIGIT
TEMP ← TEMP / 10
Endwhile
If REV = N
Print "Palindrome"
Else
Print "Not Palindrome"
Stop
Pascal Program
program PalindromeNumber;
var
N, TEMP, REV, DIGIT: integer;
begin
writeln('Enter a number: ');
readln(N);
TEMP := N;
REV := 0;
while TEMP > 0 do
begin
DIGIT := TEMP mod 10;
REV := REV * 10 + DIGIT;
TEMP := TEMP div 10;
end;
if REV = N then
writeln('Palindrome')
else
writeln('Not Palindrome');
end.
Python Program
N = int(input("Enter a number: "))
TEMP = N
REV = 0
while TEMP > 0:
DIGIT = TEMP % 10
REV = REV * 10 + DIGIT
TEMP = TEMP // 10
if REV == N:
print("Palindrome")
else:
print("Not Palindrome")
Problem 7
Write an algorithm to find the sum of digits of a number.
Algorithm Pseudocode
Start
Read N
SUM ← 0
While N > 0
DIGIT ← N mod 10
SUM ← SUM + DIGIT
N ← N / 10
EndWhile
Print SUM
Stop
Pascal Program
program SumOfDigits;
var
N, SUM, DIGIT: integer;
begin
writeln('Enter a number: ');
readln(N);
SUM := 0;
while N > 0 do
begin
DIGIT := N mod 10;
SUM := SUM + DIGIT;
N := N div 10;
end;
writeln('Sum of Digits = ', SUM);
end.
Python Program
N = int(input("Enter a number: "))
SUM = 0
while N > 0:
DIGIT = N % 10
SUM = SUM + DIGIT
N = N // 10
print("Sum of Digits =", SUM)
Problem 8
Write an algorithm to count the number of digits in a number.
Algorithm Pseudocode
Start
Read N
COUNT ← 0
While N > 0
COUNT ← COUNT + 1
N ← N / 10
Endwhile
Print COUNT
Stop
Pascal Program
program CountDigits;
var
N, COUNT: integer;
begin
writeln('Enter a number: ');
readln(N);
COUNT := 0;
while N > 0 do
begin
COUNT := COUNT + 1;
N := N div 10;
end;
writeln('Number of digits = ', COUNT);
end.
Python Program
N = int(input("Enter a number: "))
COUNT = 0
while N > 0:
COUNT = COUNT + 1
N = N // 10
print("Number of digits =", COUNT)
Problem 9
Write an algorithm to check whether a year is a leap year.
Algorithm Pseudocode
Start
Read YEAR
If (YEAR mod 400 = 0)
Print "Leap Year"
Else if (YEAR mod 100 = 0)
Print "Not Leap Year"
Else if (YEAR mod 4 = 0)
Print "Leap Year"
Else
Print "Not Leap Year"
Stop
Pascal Program
program LeapYear;
var
YEAR: integer;
begin
writeln('Enter the year: ');
readln(YEAR);
if (YEAR mod 400 = 0) then
writeln('Leap Year')
else if (YEAR mod 100 = 0) then
writeln('Not Leap Year')
else if (YEAR mod 4 = 0) then
writeln('Leap Year')
else
writeln('Not Leap Year');
end.
Python Program
YEAR = int(input("Enter the year: "))
if YEAR % 400 == 0:
print("Leap Year")
elif YEAR % 100 == 0:
print("Not Leap Year")
elif YEAR % 4 == 0:
print("Leap Year")
else:
print("Not Leap Year")
Problem 10
Write an algorithm to search an element in a list.
Algorithm Pseudocode
Start
Read N
Read array A
Read key
For i ← 1 to N
If A[i] = key
Print "Found"
Stop
EndFor
Print "Not Found"
Stop
Pascal Program
program LinearSearch;
var
A: array[1..100] of integer;
N, i, key: integer;
found: boolean;
begin
writeln('Enter number of elements: ');
readln(N);
writeln('Enter array elements: ');
for i := 1 to N do
readln(A[i]);
writeln('Enter key to search: ');
readln(key);
found := false;
for i := 1 to N do
begin
if A[i] = key then
begin
writeln('Found');
found := true;
break;
end;
end;
if not found then
writeln('Not Found');
end.
Python Program
N = int(input("Enter number of elements: "))
A = []
print("Enter array elements:")
for i in range(N):
A.append(int(input()))
key = int(input("Enter key to search: "))
found = False
for i in range(N):
if A[i] == key:
print("Found")
found = True
break
if not found:
print("Not Found")
No comments:
Post a Comment