Pseudocode_Examples_Procedures_Functions_Corrected
Pseudocode_Examples_Procedures_Functions_Corrected
• Pseudocode:
• PROCEDURE WelcomeMessage(username)
• currentDate = GetCurrentDate()
• PRINT "Hello, " + username + "! Today's date
is: " + currentDate
• PRINT "Welcome to the learning portal!"
Example 2: Physics Energy
Calculation
• Scenario: Calculate energy using E = mc^2.
• Pseudocode:
• FUNCTION CalculateEnergy(mass,
speed_of_light)
• RETURN mass * speed_of_light *
speed_of_light
• END FUNCTION
Example 3: Rectangle Area
Calculation
• Scenario: Calculate the area of a rectangular
room.
• Pseudocode:
• FUNCTION CalculateArea(length, width)
• RETURN length * width
• END FUNCTION
• Pseudocode:
• PROCEDURE
GenerateMultiplicationTable(number)
• PRINT "Multiplication Table for " + number +
":"
• FOR i FROM 1 TO 10
Example 5: Shopping Cart
Calculation
• Scenario: Calculate the total price of items in a
shopping cart.
• Pseudocode:
• FUNCTION CalculateTotal(cart)
• total = 0
• FOR item IN cart
• total = total + item.price
• END FOR
Example 6: Factorial Calculation
• Scenario: Calculate factorial for permutations.
• Pseudocode:
• FUNCTION Factorial(number)
• IF number = 0 OR number = 1 THEN
• RETURN 1
• ELSE
• RETURN number * Factorial(number - 1)
• END IF