Learn ICT Faster and Better
Theory, Programming Exercises, Past Paper Questions and Answers, Assignments with Answers Practical Videos Learn ICT By Examples
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")
Python function which accept number as input and return it in words
Exercises for Python| User defined function in Python| Function accept number return in words| Exercises for Python List, String, functions and operators
ICT A/L
#function defined to accept two digit number as parameter and print the number in words
#function defined to accept three digit number as parameter and print the number in words using the digit1n2rword
def digit3word(num):
if num < 100:
return digit1n2rword(num)
hundreds = num // 100
remainder = num % 100
if remainder == 0:
return digit1n2rword(hundreds) + " Hundred"
else:
return digit1n2rword(hundreds) + " Hundred " + digit1n2rword(remainder)
#function defined to accept any digit number as parameter and print the number in words using the function digit3word
def anyDigitWord(num):
if num == 0:
print("Zero")
return
place_values = ["", "Thousand", "Million", "Billion", "Trillion"]
words = []
i = 0
while num > 0:
part = num % 1000
if part != 0:
text = digit3word(part)
if place_values[i]:
text += " " + place_values[i]
words.insert(0, text)
num //= 1000
i += 1
print(" ".join(words))
Main Program which call the anyDigitWord function with given numbers
Match each of the given phrases relating to commerce with the most suitable item from the list below:
List = {advertising as a revenue model, credit-cards, Government e-Tendering services, Government to Citizen (G2C) service, group purchasing, harmful explosives, online market, payment gateway, perishable goods, social commerce, subscription as a revenue model, traditional marketplace}
Phrase
List Item
A place where buyers and sellers interact physically for exchange goods and services for a place.
These are usually prohibited to be sold or purchased through e-commerce systems
Users pay a regular fee to have full access to a website of a business
A subset of e-commerce that involves using social media to assist in the online buying and selling of products and services
Facilitates a payment transaction by the transfer of information between the e-commerce application and the back-end financial services providers through secure means
The renewal of vehicle revenue license using the Online Vehicle Revenue License Service offered by the relevant government office.
Question 2
In an emergency health problem where people have to stay at home for long period, the shops within the area remain closed for regular business activities. Under such circumstances the shops within a village or nearby town can help their community by practicing their business through e-commerce.
Consider the above scenario, fill the blanks in the following statements with suitable phrases from the given list.
List ={ advertising banners, an online marketplace, a shopping cart, a web product catalogue, cash-on-delivery, credit-cards, discount pricing, group purchasing, payment gateway, click and brick, pure clicks, subscription as a revenue model}
Phrase
List Item
In this emergency situation, shops follow the …………………….business model.
Shops must use ……………………… to allow customers to purchase more than one type of product in a single transactions.
The e-commerce site for cash shop can implement ………………….to display their products to the customers.
For business owners who cannot use payment gateway through online fund receipts and for the customers who do not have any online mode of payment can still be supported through ……………………..
------------------is one of the best ways to reduce the overhead costs of delivery within a local area such as a lane, street or housing scheme
The local shop owners can establish ………………….to serve their community better by enabling access to each shop’s services through a common portal.
Question 3
Fill the blanks in the following statements with suitable words from the given list of words.
List ={ Encryption, Copyright, Phishing, Plagiarism, Software Piracy}
Phrase
List Item
…………….helps to ensure the confidentiality of our data and information.
………………..is the attempt to acquire sensitive information by pretending as a trustworthy entity in an electronic communication.
The illegal copying, distribution, or use of software is known as ……………….and …………………….helps us to protect our software from such illegal use.
Question 4
Match each of the given phrases relating to computer networks with the most suitable item from the list below.
List ={ADSL Connection, DSL Connection, FTP, HTTP, Internet Layer, Malware, Phising, TCP, Tranport Layer, UDP}
Phrase
List Item
A simple and query based communication model with a minimum use of protocol mechanisms applied in trasport layer.
A protocol for data communication in the World Wide Web
The layer that defines the addressing and routing structures used for the TCP/IP protocol suite in the TCP/IP model.
The process of attepting to get sensitive information from smeone by pretending as a trustworthy person.
The connection that allows the data transmission at much greater speed and capacity than the narrowband services.
Important Notes:
Pure Brick-and-Mortar:
Traditional businesses with physical stores only and no online presence.
Example: A local grocery store with no website.
Brick-and-Click:
Businesses that have both physical stores and an online presence.
Example: Walmart or Target – customers can shop in-store or online.
Pure Click:
Businesses that operate only online, with no physical storefronts.
Example: Amazon or Netflix.
Click-and-Mortar (Same as Brick-and-Click):
This is another term for Brick-and-Click businesses combining offline and online operations.
Physical memory refers to the actual hardware (RAM) installed in a computer. It's where data and programs are stored temporarily while they are being used or executed.
Pages and Frames
In operating system memory management, pages and frames are fundamental concepts related to paging, a memory management scheme that eliminates the need for contiguous allocation of physical memory. Pages and Frames are different aspects of memory.
Comparison of Pages and Frames
Feature
Pages
Frames
Definition
Fixed-size blocks of a logical (virtual) address space
A file system is a method to store, organise, retrieve and manage data on storage devices (Hard disks, SSD, USB) by Operating system.
There are many different file systems available. Key functions of file systems are: structure data into files and folders, tracks where data is physically stored on the disks, manage permissions and user access to files, supports creating, reading, writing, deleting and modifying files. These functions can be varied file system to file system. One files system may not support with other file system. Diffrent operating systems uses different file systems.
Some of the widely used file systems are given below
FAT (File Alloction Table)
FAT is the file systems introduced with Microsoft Disk Operating System (MS OS).
FAT uses a File Allocation Table (FAT) to keep track of files in the storage devices.
FAT and the root directory reside at a fixed location of the volume so that the system's boot files can be correctly located.
To protect a volume, two copies of the FAT are kept.
There are many variants such as Variants: FAT12, FAT16, FAT32
The advantages of FATare simple, widely compatible
The dis advantages of FAT are Limited size (4GB for FAT 32), It is not very secure
exFAT (Extended File Allocation Table)
exFAT is used at USB drives, SD cards (cross-platform)
Advantages are Supports large files, compatible with Windows & macOS
Disadvantages are No journaling, less robust for system drives
NTFS
(New Technology File System) is a proprietary file system developed by Microsoft. This is improvement of FAT. Windows (default)
This improvement includes The capability to recover from some disk-related errors automatically, which FAT cannot.
Support with Unicode encoding system
Improved support for larger hard disks.
Better security as permissions, journaling and encryptions are used to restrict access to specific files to approved users.
Disadvantages Limited support on non-windows systems
ext (Extended File System)
(Extended File System): Commonly used in Linux distributions, with versions like ext4 offering journaling and improved performance.
There are many variant available ext2, ext3, ext4 in Linux
Advantages are ext4 supports journaling, large files, and volumes
Disadvantages are Limited compatibility with windows/macOs
HFS+ and APFS:
Used by macOS, with APFS designed for solid-state drives, providing features like snapshots and encryption.
Older macOs used HFS+ file systems and APFS is used by modern macOS
Advatages of APFS are better performance, encryption and snapshots
Disadvantages not natively writable on non-Apple systems
Partitioning of a Disk
Partitioning is the process of dividing a physical storage device into separate independent sections.These independent section is called partitions. This partitioning is used for hard disk or SSD. Each partition can have its own file system, operating system, or usage purpose.
Why Partition a Disk
There are many advantages of patiting a disk. Some of them are given below
Organize Data – Keep system files separate from personal data.
Dual Boot – Install multiple operating systems (e.g., Windows + Linux).
Improve Performance – Manage storage more efficiently.
Backup & Recovery – Isolate system and recovery partitions.
Security – Limit access between partitions.
Partitioning Schemes
MBR (Master Boot Record): Older system, supports up to 2 TB and 4 primary partitions.
GPT (GUID Partition Table): Modern standard, supports larger disks and up to 128 partitions. Required for UEFI systems.
Types of Partitions
There are several types of Partitions are available
Primary Partition: Bootable partition that can host an OS (max 4 primary partitions per disk in MBR).
Extended Partition: A special type that holds multiple logical partitions (used when you need more than 4 partitions in MBR).
Logical Partition: A sub-part of an extended partition. Useful for organizing data.
EFI/System Partition: Required for booting in UEFI systems (in GPT partitioning).
Disk Formatting
Disk formatting is the process of preparing a storage device (like a hard drive or SSD) to store data.
There are two main types of disk formatting is available. They are Low-Level Formatting and High-Level Formatting.
Low-level formatting
Low-level formatting is the process of physically preparing the disk by creating sectors and tracks on the surface of the disk. Low-level formatting is done at the factory for modern drives.
It defines how data will be physically stored on the disk. It is Rarely done by users today. It Lays down the magnetic markers for sectors/tracks.
High-Level Formatting
High-level formatting is the process of setting up a file system on the disk. Different Operating system can setup different file systems example windows can setup NTFS or FAT32 same time Linux can setup ext4. Operating system can store and manage files after the High-Level Formatting is done.
Performed by the user (e.g., using tools like Windows Disk Management or mkfs in Linux or format in DOS). Tasks are done by High-Level formatting: Initializes the file system. Creates boot sector, file allocation table, root directory, etc. High-Level Formatting Can be quick format which just sets up file system structures, or full format which scans for bad sectors too.
Ex : Using DOS command; if we use to full formating c: drive format c: quick format c: drive format C: /q formating c: drive with DOS intalled format c:/s
The Different between Word Processing and Desktop Publishing (DTP)
Word processing is creating, editing, formatting and printing text based documents using computer software. This software is called Word processing software. Examples for some of the word processing software are Micro soft word, Open office writer, Apple Pages, Google docs and Word perfect etc.
In other hand Desk top publishing is used to create high quality, visually rich printed or digital documents using software. This software is called desk top publishing software. Example for some of the desk top publishing software is Adobe InDesign, QuarkXPress, Scribus (Open source) and PageMaker.
Description
Word Processing
Desk top publishing
Use
Text-heavy documents
For professional-looking, visually complex layouts
Software
Microsoft Word, Google Docs, Open Office Writer, Apple Pages
Fragmentation is the unintentional division of Disk into many small free areas that cannot be used effectively due to scattered storage of file fragments.
It Occurs when files are stored in non-contiguous sectors on a disk. File operations are dynamic nature, where files grow and shrink, and blocks of data become available after deletions.
Fragmented files require head to move more for read or write operations, It increases access times and reduceds performance, mainly in hard disks
Defragmentation
Defragmentation is a process that locates and eliminates file fragments by rearranging them.
The defragmentation tool analyzes the disk, identifies fragmented files, and moves them so that each file occupies a single contiguous block of space. It also consolidates free space to minimize fragmentation in the future.
Defragment a disk periodically is advisable, if it is heavily used.
Modern operating systems often automatically handle fragmentation using inbuilt tool.
Example:
Windows: The "Defragment and Optimize Drives"
Linux: While Linux filesystems are generally more resistant to fragmentation, tools like e4defrag can be used for ext4 filesystems.
Solid-state drives (SSDs) do not require defragmentation. Its architecture allows for equal access times regardless of data location.
Defragmenting an Solid-state drives(SSD) can reduce its lifespan due to unnecessary write cycles.
Benefits of Defragmentation
Improved Performance:
By reducing the time it takes for the disk to access files, defragmentation can lead to faster boot times, quicker file access, and overall improved system responsiveness.
Extended Drive Life:
Although the effect is more pronounced on Hard Disks, better performance can lead to less wear and tear over time.
Limitations of Defragmentation
Time-Consuming:
Depending on the size of the disk and the level of fragmentation, defragmentation can take a significant amount of time.
Temporary Impact:
After defragmentation, further file operations may lead to fragmentation again, necessitating ongoing maintenance.