0% found this document useful (0 votes)
6 views17 pages

Algorithm N

The document provides a series of pseudocode algorithms for various mathematical and logical operations, including calculating areas, discounts, VAT, simple interest, and more. Each algorithm is structured with clear steps for user input and output, demonstrating fundamental programming concepts. It covers a wide range of scenarios, from basic arithmetic to conditional statements and user interactions.

Uploaded by

hugginssasha420
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views17 pages

Algorithm N

The document provides a series of pseudocode algorithms for various mathematical and logical operations, including calculating areas, discounts, VAT, simple interest, and more. Each algorithm is structured with clear steps for user input and output, demonstrating fundamental programming concepts. It covers a wide range of scenarios, from basic arithmetic to conditional statements and user interactions.

Uploaded by

hugginssasha420
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ALGORITHMS / PSEUDOCODES

An algorithm is a step-by-step method of solving a problem. It is commonly


used for data processing, calculation and other related computer and
mathematical operations. An algorithm is also used to manipulate data in
various ways, such as inserting a new data item, searching for a particular item
or sorting an item.

A pseudocode is an informal high-level description of the operating principle of


a computer program or other algorithm. It uses the structural conventions of a
normal programming language, but is intended for human reading rather than
machine reading.

1. Write a pseudocode algorithm that accepts the value of the side of a


square and display its area. (area = side * side).
Step 1Start
Step 2Read Side
Step 3Area = Side * Side
Step 4Write Area
Step 5Stop

2. As part of Christmas sale, Caribe Shop has decided to give a 15%


discount on all items. Write a pseudocode that will accept the price of an
item and calculate and display the price and discount.
Step 1Start
Step 2Read Price
Step 3Discount = (Price * 0.15)
Step 4Newprice = (Price – Discount)
Step 5Write Discount
Step 6Write Newprice
Step 7Stop

3. Write a pseudocode that will accept the price of an item and calculate its
new price after a discount of 25%.
Step 1Start
Step 2Read Price
Step 3Discount = (Price * 0.25)
Step 4Newprice = (Price – Discount)
Step 5Write Newprice
Step 6Stop

4. The Government of Sands has decided to introduce VAT (Value Added


Tax) for all items being purchased. So all items sold will add 15% of its

1
price as VAT. Write a pseudocode that will accept the price of an item and
calculate and display its new price including VAT.
Step 1Start
Step 2Read Price
Step 3VAT = (Price * 0.15)
Step 4Newprice = (Price + VAT)
Step 5Write Newprice
Step 6Stop

5. Write a pseudocode that will accept the values for Principal, No of Years
and interest rate and calculate and display the simple interest. (Simple
Interest = Principal * Years * Rate)
Step 1Start
Step 2Read Principal
Step 3Read Years
Step 4Read InterestRate
Step 5SimpleInterest = (Principal * Years * InterestRate)
Step 6Write SimpleInterest
Step 7Stop

6. Write a pseudocode that prompts the user to enter the base and height of
a triangle and calculate its area. (area = ½ * base * height)
Step 1Start
Step 2Write “Enter base “
Step 3Read Base
Step 4Write “Enter height “
Step 5Read Height
Step 6Area = (0.5 * Base * Height)
Step 7Write Area
Step 8Stop

7. Write a pseudocode that prompt the user to enter the radius of a circle
and calculate its circumference (2 * 3.142 * radius)
Step 1Start
Step 2Read Radius
Step 3Circumference = (2 * 3.142 * Radius)
Step 4Write Circumference
Step 5Stop

8. Write pseudocode that will create a conversion table that will convert
degree Celsius to degree Fahrenheit. Prompt the user to enter the

2
temperature in degree Celsius and display the temperature in Fahrenheit.
(Fahrenheit = 32 + (9 * Celcius / 5)
Step 1Start
Step 2Write “Enter degree Celsius “
Step 3Read Celsius
Step 4Fahrenheight = 32 + (9 * Celsius / 5)
Step 5Write Fahrenheight
Step 9Stop

9. Write a pseudocode that will read in the money in US dollars and convert
and display it in EC dollars. (1 US = 2.70 EC) It should be displayed in
the following format: 2 US = 5.40 EC.
Step 1Start
Step 2Read USdollar
Step 3ECdollar = (USdollar * 2.70)
Step 4Write ECdollar
Step 5Stop

10. Write a pseudocode to find the largest between two numbers,

Step 1Start
Step 2“Enter two numbers”
Step 3Read Num1, Num2
Step 4If Num1 > Num2 then
Set Large Num1
Else
Set Large Num2
Endif
Step 5Write Large
Step 6Stop

11. Write a pseudocode that will accept two numbers from the user and store
them in two variables and output the interchanged values.

Step 1Start
Step 2Write “Enter first number “
Step 3Read Num1
Step 4Write “Enter second number “
Step 5Read Num2
Step 6Temp = Num1
Step 7 Num1 = Num2

3
Step 8 Num2 = Temp
Step 9 Write Num1
Step 10 Write Num2
Step 11 Stop

12. Write a narrative algorithm that will prompt the user to enter a value and
display its square.
Step 1Start
Step 2Write “Enter number ‘
Step 3Get Num
Step 4Calculate the Square by using the formula Num * Num and
store in Square
Step 5Display the Square
Step 6Stop

13. You need to calculate the perimeter of a rectangle using its length and
width.
Write a narrative algorithm that will accept the length and width and
calculate and print the perimeter of the rectangle. (Perimeter = 2 * (L + W)

Step 1Start
Step 2Get L
Step 3Get W
Step 4Calculate the Perimeter by using the formula 2 * (L + W) and
store in Perimeter
Step 5Display the Perimeter
Step 6Stop

14. Write a pseudocode that will prompt the user to enter the score of a
student and display the message “distinction” if the score is 80 or more.

Step 1Start
Step 2Write “Enter Student’s Name ”
Step 3Read Name
Step 4Write “Enter Student’s Grade ”
Step 5Read Score
Step 6If Score >=80 then
Write “Distinction”
Endif

4
Step 7Stop

15. Write a pseudocode that will accept the age of a person and display the
message “ You are eligible to vote “ if the age is more than or equal to 18.

Step 1Start
Step 2Read Age
Step 3If age >=18 then
Write “You are eligible to vote”
Endif
Step 4Stop

16. Write a pseudocode that will accept the age of a person and display the
message “ You are eligible to vote “ if the age is more than or equal to 18.

Step 1Start
Step 2Read Age
Step 3If age >=18 then
Write “You are eligible to vote”
Endif
Step 4Stop

17. Write a pseudocode that will allow the user to enter the mark of a subject
for a student and display the message “Pass if the score is more than or
equal to 60. Otherwise, display the message “Fail”.

Step 1Start
Step 2Write “Enter student’s mark “
Step 3Read mark
Step 4If mark >=60 then
Write “Pass”
Else
Write “Fail”
Endif
Step 5Stop

18. Write a pseudocode that will accept two numbers and find their sum and
difference. If the sum is more than the difference, display the sum
otherwise the difference.

5
Step 1Start
Step 2Read num1
Step 3Read num2
Step 4Sum = num1 + num 2
Step 5Diff = num1 – num2
Step 6If sum > diff then
Write sum
Else
Write diff
Endif
Step 7Stop

19. Write a pseudocode that will prompt the use to enter a number. If number
entered is more than 10 displays the message “the number is more than
10” otherwise display “the number is less than 10”.

Step 1Start
Step 2Write “Enter number “
Step 3Read num
Step 4If num >10 then
Write “The number is more than 10”
Else
Write “The number is less than 10”
Endif
Step 5Stop

20. Students who got 40% in their end of term examination is given a
moderation mark of 5. Write a pseudocode that will prompt the user to
enter the score of a student and display their original score and
moderated score.

Step 1Start
Step 2Write “Enter student’s score “
Step 3Read score
Step 4ModerationMark = 5
Step 5If Score = 40 then
Moderationscore = (score + moderationmark)
Else
Moderationscore = score
Endif
Step 6Write “The original score is “, score
Step 7Write “The moderation score is “, moderationscore

6
Step 8Stop

21. Write a pseudocode that will prompt the user to enter two unequal
numbers and display the larger between them.

Step 1Start
Step 2Write “Enter the first number “
Step 3Read Num1
Step 4Write “Enter a different second number “
Step 5Read Num2
Step 6If Num1 > Num2 then
Write Num1 “is the largest”
Else
Write Num2 “is the largest”
Step 7Stop

22. Write a pseudocode that will prompt the user to enter three unequal
numbers and display the smallest among them.

Step 1 Start
Step 2 Write “Enter the first number “
Step 3 Read Num1
Step 4 Write “Enter a different second number “
Step 4 Read Num2
Step 5 Write “Enter a different third number “
Step 6 Read Num3
Step 7 If Num1 > Num3 and Num2 > Num3 then
Write Num3 “in the smallest”
Else
If Num3 > Num1 and Num2 > Num1 then
Write Num1 “is the smallest”
Else
If Num1 > Num2 and Num3 > Num2 then
Write Num2 “is the smallest”
Endif
Step 8 Stop

23. Write a pseudocode that will prompt the user to enter the name and price
of an item. If the price is more than $350, print the price of the item
otherwise output the name of the item.

7
Step 1Start
Step 2Write “Enter the name of the item “
Step 3Read Item
Step 4Write “Enter the price of the item “
Step 5Read Price
Step 6If Price >350 then
Write Price
Else
Write Item
Endif
Step 7Stop

24. Write a pseudocode that will accept the prices of three items and if the
total price of the three items is more than $500, a discount of 15% of the
total price is given. Display the Total amount if there is no discount,
otherwise display the new total amount after discount.

Step 1Start
Step 2Write “Enter the price of the first item “
Step 3Read Price1
Step 4Write “Enter the price of the second item “
Step 5Read Price2
Step 6Write “Enter the price of the third item “
Step 7 Read Price3
Step 8TotalAmount = (Price1 + Price2 + Price3)
Step 9If TotalPrice >500 then
Discount = (TotalAmount * 0.15)
NewTotalAmount = (TotalAmount – Discount)
Write “The new total amount after discount “,
NewTotalAmount
Else
Write “The total amount is “, TotalAmount
Endif
Step 10 Stop

25. Write a pseudocode that will accept a value for an integer and display the
message “positive” or negative” based on the integer entered.

Step 1Start
Step 2Read num
Step 3If Num >= 0 then
Write “Positive”
Else

8
Write “Negative”
Endif
Step 4Stop

26 An insurance company gives their sales men a commission of 5% if their


total sale is more than $50,000. Write a pseudocode that prompts the
user to enter the total sales and calculate and display their commission.

Step 1Start
Step 2Write “Enter total sales “
Step 3Read TotalSales
Step 4If TotalSales > 50000 then
Commission = (TotalSales * 0.05)
Write “The commission is”, Commission
Endif
Step 5Stop

27. Write a pseudocode that will accept a number. If the number is more than
10, then subtract 10 from it and multiply by 3, otherwise add 10 and
multiply by 2 and display the results.

Step 1Start
Step 2Read num
Step 3If num > 10 then
newnum:= (num - 10) * 3
else
newnum:= (num + 10) * 2
Write “The New Number is “, newnum
Endif
Step 4Stop

28. An exam board uses the following criteria for assigning grades for
students:
Score Grade
80 – 100 % Excellent (E)
60 - 79% Good (G)
45 - 59% Satisfactory (S)

9
33- 44% Unsatisfactory (US)
Below 33% Very Unsatisfactory (VUS)
Write a pseudocode algorithm that will accept the score of a student in a
test and display the grade (E,G,S, US or VUS) based on the above
criteria.

Step 1Start
Step 2Read Score
Step 3If Score >=80 and Score <101 then
Write “The grade is “, E
Else
If Score >= 60 and Score < 80 then
Write “The grade is “, G
Else
If Score >= 45 and Score < 60 then
Write “The grade is “, S
Else
If Score >= 33 and Score < 45 then
Write “The grade is “, US
Else
If Score < 33 then
Write “The grade is “, VUS
Endif
Step 4Stop

29. A talent show at St. George High School attracts the following rates:
18 years or more $25
10 – 12 years $15
Below 10 years $5

Write pseudocode that will accept the age of a person attending the show
and display the correct rate.

Step 1Start
Step 2Read Age

10
Step 3If Age >=18 then
Write “The rate is $25“
Else
If Age >= 10 and Age < 13 then
Write “The rate is $15“
Else
If Age < 10 then
Write “The rate is $5“
Endif
Step 4Stop

30 Write a pseudocode that will prompt the user to enter a number and a
character. If the character is “S” the program should display the
Square of the number and if it is “C” it should display the Cube of the
number and if it is “H’ it should display half of the number.

Step 1Start
Step 2Write “Enter a number “
Step 3Read Number
Step 4Write “Enter a character “
Step 5Read Character
Step 6If Character = “S” then
Square is (Number * Number)
Write Square
Else
If Character = “C” then
Cube = (Number * Number * Number)
Write Cube
Else
If Character = “H” then
Half = (Number / 2)
Write Half
Endif
Step 7 Stop

31. The Water department uses the following charges for their customers:

11
1000 gallons or more $100 as fixed charge plus 5 cents per gallon
500 – 999 gallons $ 50 as fixed charge plus 3 cents per gallon
Below 500 gallons $ 50 as fixed charge plus 2 cents per gallon

Write a pseudocode that will accept the name and the volume of water
used by a customer and display their bill with the name and charge.

Step 1Start
Step 2 Read Name
Step 3Read Gallons
Step 4If Gallons >= 1000 then
FixedCharge = 100
OtherCharges = (Gallons * 0.05)
TotalCharges = (FixedCharges + OtherCharges)
Write “Customer’s name “, Name
Write “The total charges is “, TotalCharges
Else
If Gallons >= 500 and Gallons <1000 then
FixedCharge = 50
OtherCharges = (Gallons * 0.03)
TotalCharges = (FixedCharges + OtherCharges)
Write “Customer’s name “, Name
Write “The total charges is “, TotalCharges
Else
If Gallons < 500 then
FixedCharge = 50
OtherCharges = (Gallons * 0.02)
TotalCharges = (FixedCharges + OtherCharges)
Write “Customer’s name “, Name
Write “The total charges is “, TotalCharges
Endif
Step 5 Stop

32. Write a pseudocode that will accept the time of the day and display the
message “Good Morning”, “Good Afternoon” and “Good night” based on
the time entered.

Step 1Start
Step 2 Read Time
Step 3If Time >= 12 midnight and Time < 12 noon then
Write “Good Morning”
Else
If Time >= 12 noon and Time < 6 pm then
Write “Good Afternoon“
Else

12
If Time >= 6 pm and Time < 12 midnight then
Write “Good Night“
Endif
Step 4 Stop

33. A School uses the following criteria for placement of students in their fifth
from classes:
Subject passes Class
9 to 10 subject passes Form 5 I
7 to 8 subject passes Form 5 II
5 to 6 subject passes Form 5 III
Below 5 subjects passes Form 5 IV
Write pseudocode that will accept the name and total number of subjects
passed by a student and print their name and class.

Step 1Start
Step 2 Read Student
Step 3Read SubjectPasses
Step 4If SubjectPasses >= 9 and SubjectPasses < 11 then
Write Student “will be placed in Form 5 I“
Else
If SubjectPasses >= 7 and SubjectPasses < 9 then
Write Student “will be placed in Form 5 II“

Else
If SubjectPasses >= 5 and SubjectPasses < 7 then
Write Student “will be placed in Form 5 III“
Else
If SubjectPasses < 5 then
Write Student “will be placed in Form 5 IV“
Endif
Step 5 Stop

34. Employees become “pensionable” based on the following criteria.


(a) Status is “appointed” and experience is more than 10 years
(b) Status is “appointed” OR experience is more than 10 – 20 years
(c) Experience is more than 20 years.

Write a pseudocode that will accept the name, status and experience of
an employee and output their name and a message “Pensionable” if they

13
are pensionable.

Step 1Start
Step 2 Read Employee
Step 3Read Status
Step 4Read Experience
Step 5If Status = “Appointed” and Experience > 10 then
Write Employee “is Pensionable“
Else
If Status = “Appointed” or Experience > 10 and Experience
< 21 then
Write Employee “is Pensionable“
Else
If Experience > 20 years then
Write Employee “is Pensionable“
Endif
Step 6 Stop

35. Employees of Shopmart is paid daily with a salary at an hourly rate of $10.
If they work more than 8 hours in a day, they will get double the hourly
rate of salary for the total worked in excess of 8 hours worked in a day
and print their salary.

Step 1Start
Step 2 Read Employee
Step 3Read Rate
Step 4Read Hours
Step 5If Hours = 8 then
Salary = (Rate * Hours)
Write Salary
Else
If Hours >8 then
Salary = (8 * Rate) + Hours – 8 * (2 * Rate)
Write Salary
Step 6 Stop

36. Write a pseudocode to print the numbers from 1 to 15.

Step 1Start
Step 2 for num = 1 to 15
Step 3Read num
Step 4num = num + 1
Step 5endfor

14
Step 6write num
Step 7Stop

37. Write a pseudocode that will print the numbers between 500 and 800.

Step 1Start
Step 2 for num = 500 to 800
Step 3Read num
Step 4num = num + 1
Step 5endfor
Step 6write num
Step 7Stop

38. Write a pseudocode and draw a flowchart that will accept 30 numbers
from the user and display its total.

Step1 Start
Step 2For i = 1 to 30
Step 3Read Num
Step 4i = i + 1
Step 5 Total = Total + Num
Step 6EndFor
Step 7Write Total
Step 8Stop

39. Write a pseudocode that will accept 25 students in a class and display the
age of the oldest student.

Step1 Start
Step 2For i = i to 25
Step 3Read Student
Step 4Read Age
Step 5If age > age then
Write student
Write age
endif
Step 6Endfor
Step 7Stop
15
40. Write a pseudocode that will accept the gender of the student for a school
and output the number of males and females separately. The
pseudocode stops when the user enters “STOP”.

Step 1Start
Step 2While A <> “Stop” Do
Step 3Read Gender
Step 5If Gender = “M” then
Write Item
Write Price
Endif
Step 6Stop

41. Write a pseudocode that will accept the names and prices of a set of
items and print the names and prices of items that cost more than $100.
The pseudocode stops when the user enters “STOP” for the item name.

Step 1Start
Step 2While X <> “Stop” Do
Step 3Read Item
Step 4Read Price
Step 5If Price >100 then
Write Item
Write Price
Endif
Step 6Stop

42. Net salaries of employees are paid after the calculation of their deductions
and allowances. The following rates are used for calculating these
allowances and deductions.

Allowances Deductions
HRA 15% of Basic SS 7% of Basic
16
DA 10% of Basic Levy 1% of Basic
EA 5% of Basic
TA 12% of Basic
In order to calculate the Gross salary the following formulas are used:
Gross salary = Basic salary + allowances
Net salary = Gross salary – deductions

Write a pseudocode that will prompt the use to enter the name and basic
salary of an employee and output their name, basic salary, allowances,
deductions, gross salary and net salary with appropriate labels

Step 1Start
Step 2Write “Enter employee’s name ”
Step 3Read empname
Step 4Write “Enter basic salary “
Step 5Read basic
Step 6HRA = basicsal * 0.15
Step 7DA = basicsal * 0.10
Step 8EA = basicsal * 0.05
Step 9RA = basicsal * 0.12
Step 10 SS = basicsal * 0.07
Step 11 Levy = basicsal * 0.01
Step 12 Allowances = HRA + DA + EA + TA
Step 13 Deductions = SS + Levy
Step 14 Grosssal = basicsal + allowances
Step 15 Netsal = grosssal – deductions
Step 16 Write “Employee’s name “, empname
Step 17 Write “Basic salary ‘, basicsal
Step 18 Write “Allowances “, allowances
Step 19 Write “Deductions “, deductions
Step 20 Write “Gross salary “, grosssal
Step 21 Write “Net salary “, netsal
Step 22 Stop

17

You might also like