Problem 2: The following pseudocode and flowchart have been designed to get an integer number from the user and print if it is a perfect
Problem 2: The following pseudocode and flowchart have been designed to get an integer number from the user and print if it is a perfect number or not.
Note: a perfect number is a positive integer which is equal to the sum of its proper divisors, excluding itself. For example 6 and 28 are perfect numbers because 6 = 1+2+3 and 28=1,2,4,7,14.
1: Start
2: num = 0
3: sum = 1
4: divider = 2
5: Read (num)
6: While ((num / 2) >= divider) DO
7: IF (num % divider == 0) Then
8: sum=sum+ divider
9: End IF
10: divider = divider + 1
11: End While
12: IF (num == sum AND num != 1) Then
13: Print (num , is a perfect number.)
14: Else
15: Print (num , is not a perfect number.)
16: End IF
17: End
i. Using a trace table (one per input), trace the algorithm for the following values and show the output. See the end of document for an example trace table using input 7. 25, 1, 0, 6, 28
ii. Modify the psuedocode or the flowchart in order to print out all the perfect numbers between a range of values given by the user, for example between 1 and 1000, or 200 and 800, etc
Trace Table: How to make a trace table for Part A, Problem 2 i) with 7 as a user input. (Note: Lab 0 also contains another example of a trace table for a different problem)Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started