0% found this document useful (0 votes)
18 views6 pages

Pseudocode Algorithms for Counting and Summing

1. The document contains 5 pseudocode algorithms: (1) Counts the number of times the number 6 is entered among 15 random integers. (2) Counts the number of times "red" and "green" are selected as favorite colors among 10 people. (3) Records the first and last names of people in a group based on a user-input number. (4) Keeps a running total of numbers entered by the user. (5) Finds the largest number among a series of 100 user-input numbers.

Uploaded by

kymanidouglas06
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)
18 views6 pages

Pseudocode Algorithms for Counting and Summing

1. The document contains 5 pseudocode algorithms: (1) Counts the number of times the number 6 is entered among 15 random integers. (2) Counts the number of times "red" and "green" are selected as favorite colors among 10 people. (3) Records the first and last names of people in a group based on a user-input number. (4) Keeps a running total of numbers entered by the user. (5) Finds the largest number among a series of 100 user-input numbers.

Uploaded by

kymanidouglas06
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

For Loop Activity

Subject: Information Technology


Teacher: Ms. Kera Thompson-Ritchie
Due Date: October 5, 2021
Date Given: October 5, 2021
Group Members
1. Zachary Abrahams
2. Tarun Balachandar
3. Natalia Bennett
4. Kyle Brown
5. Kymani Douglas
6. Akua Latty (Absent)
1. Write a pseudocode algorithm to accept from the user fifteen integer
numbers. Count the number of times six was entered as a number. Print
the number of times six was entered.

Header To count the number of times six was entered


Declare num as integer
Num_six as integer
Start
Num_six ← 0
For counter ← 1 to 15 do
Print "Enter number"
read num
If num=6 then
Num_six ← Num_six + 1
Else
Print “Number not recorded”
Endfor
Print “The number of times six was entered as a number is” Num_six
Stop
2. Write a pseudocode algorithm to accept the favourite colour of ten
persons. Count the number of times red and green was entered. Print
the number of times red and green was entered.

Header To count the number of time red and green was entered
Declare Colour as String
Num_Green as Integer
Num_Red as Integer
START
Num_Green ← 0
Num_Red ← 0
For counter ← 1 to 10 do
Print “Enter your favourite colour”
Read Colour
If Colour=”Green” then
Num_Green←Num_Green + 1
Elseif Colour=”Red” then
Num_Red←Num_Red + 1
Else
Print “Not recorded”
Endfor
Print “The number of times green was counted is”, Num_Green
Print “The number of times red was counted is”, Num_Red
STOP
3. A pseudocode algorithm that asks the user for the number of persons
within a group. For each person it requests the person’s first name and
last name, and then prints out the full name with a message.

Header Recording the number of people in a group and their names


Declare num1 as real
person_name as string

START
Print “Enter the number of people in your group”
Read num1
For counter ←1 to num1 do
Print “Enter your first name and last name”
Read person_name
Print “Hello”, person_name, “Welcome”
Endfor
STOP
4. Write a pseudocode algorithm that reads in N numbers and keeps a
running total of their sum as it reads them. The value of N is to be
supplied by the user.

Header Adding Numbers continuously


Declare N as integer
Sum as Real
Num as Real

START
Sum ← 0
Print “How many numbers would you like to calculate?”
Read N
For counter ← 1 to N do
Print “Enter Number”
Read num
Sum ← Sum + num
Endfor
Print “The total numbers used are” N
Print “The total of all numbers is” Sum
STOP
5. Write an algorithm that will find the largest of a series of 100 numbers.
Print the largest of all the numbers entered.

Header Finding The Largest Number In A Series.


Declare num1 as Real
num2 as Real
Largest as Real
Number as Real

START
Print “Enter 2 numbers”
Read num1
Read num2
If num1 >= num2 then
Largest ← num1
Elseif num1 < num2 then
Largest ← num2
Else
Print “Invalid”
For counter ← 1 to 100 do
Print “Enter 98 numbers”
Read number
If number >= Largest then
Largest ← number
Elseif number< Largest then
Print “Not large enough”
Else
Print “Invalid”
Endfor
Print “The Largest number is”, Largest
STOP

Common questions

Powered by AI

Loop structures ensure a definite and repeated execution context, handling multiple inputs with precise iteration control. Conditional statements enhance this by providing decision-making capabilities within loops, allowing dynamic data processing like comparing values or conditionally updating results. This setup is effective for tasks like finding the largest number or computing sums across datasets, blending methodical data handling with logical decision-making to ensure efficient and accurate operation .

Initialization separates starting conditions from logic, which aids readability and debugging. The algorithm initializes 'Largest' with one of the first two numbers, then processes the entirety of the succeeding set consistently. This separation ensures clear starting values, reducing complexity and potential logical errors by consolidating comparison logic in a distinct loop block .

The algorithm initializes 'Sum' to zero and uses a for loop iterating from 1 to N, with N defined by the user. In each iteration, it reads a number into 'num' and adds it to 'Sum'. The loop's iteration range and each input's direct addition to 'Sum' ensure every valid number is included in the total. The use of a loop based on user input for N ensures flexibility and accuracy for varying input counts, assuming inputs are valid numbers.

The algorithm initially compares two numbers, assigning the larger to 'Largest'. It then iterates over 98 additional numbers. In each iteration, it updates 'Largest' if the current number is greater or equal. The lack of exception handling for non-numeric entries or special commands means valid comparisons and updates hinge on correct user input and the valid execution of the operations described. The approach is efficient given the constraints and correctly identifies the maximum.

The pseudocode initializes a counter 'Num_six' to zero. It iterates through each user input by using a for loop from 1 to 15, where each input is read into 'num'. An if condition checks if 'num' equals six, and increments 'Num_six' by one if true. This approach ensures the count accurately reflects how often 'six' was entered. After the loop, the total number of times 'six' was input is printed .

Currently, the pseudocode prints 'Not recorded' for any color that is not 'Red' or 'Green', implying all non-matching inputs are ignored. A more robust solution would include input validation or prompts for invalid data, allowing correction before proceeding, thus ensuring the user can correct mistakes, leading to more accurate data collection .

The algorithm begins by initializing 'Num_Green' and 'Num_Red' to zero. It uses a for loop to iterate for ten inputs, reading each color into 'Colour'. Within each iteration, if 'Colour' matches 'Green', it increments 'Num_Green'; if 'Colour' matches 'Red', it increments 'Num_Red'. Any other input prints 'Not recorded'. This logic ensures accurate counting by only incrementing counters when specific conditions are met .

Improvements could include input validation to ensure non-empty and proper format for names, making the user experience cleaner. The algorithm could also separate first and last names to greet users personally and integrate checks for empty or invalid entries to prevent errors. Additionally, it could store names in a list for later access or further processing, enhancing flexibility and utility.

The logic is straightforward and positively affects user experience by confirming input through a personalized message. While this interaction aids clarity, the pseudocode lacks error management, assuming correct input format without validation can lead to runtime errors if inputs are improperly formatted or missing, potentially lowering robustness in varied usage scenarios .

The algorithm uses a for loop from 1 to N set by user input, which ensures each number is read and added once. Decision-making simplifies to collecting inputs and sums without conditions during the loop. The initial sum of zero and continuous number addition correctly tracks the running total by maintaining clear, linear operations dependent entirely on user-provided count and data .

You might also like