Question

In the pseudocode below: Function Integer perfect(Integer n) Declare Integer count = 0 Declare Integer sum...

In the pseudocode below:

Function Integer perfect(Integer n)
        Declare Integer count = 0
        Declare Integer sum = 0

        While count < n
                Set count = count + 1
                Set sum = sum + count
        End While

        Return sum
End Function

Function Integer perfect_sum(Integer n)
        Declare Integer count = 0
        Declare Integer sum = 0

        While count < n
                Set count = count + 1
                Set sum = sum + perfect(count)
        End While

        Return sum
End Function    

Module main()
        Display perfect_sum(5)
End Module

What will be the output when the main module is called (separate each output with a single space)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Output:
--------
35

Explanation:
----------------
perfect(1) is 1
perfect(2) is 1+2 = 3
perfect(3) is 1+2+3 = 6
perfect(4) is 1+2+3+4 = 10
perfect(5) is 1+2+3+4+5 = 15

so, perfect_sum(5) = 1+3+6+10+15 = 35
Add a comment
Know the answer?
Add Answer to:
In the pseudocode below: Function Integer perfect(Integer n) Declare Integer count = 0 Declare Integer sum...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is wrong with the following pseudocode? Declare Count As Integer Declare TheNumber As Integer Set...

    What is wrong with the following pseudocode? Declare Count As Integer Declare TheNumber As Integer Set TheNumber = 12 For (Count = 10; Count>TheNumber; Count--) Write TheNumber + Count End For A) The limit condition in a For loop cannot be a variable B) The loop will never be entered since the initial value of Count is less than the test condition C) The loop will never end since the test condition will never be met D) A counter must...

  • Given the following pseudocode: Class Coordinate Private Real _x Private Real y Public Module set_x(Real value)...

    Given the following pseudocode: Class Coordinate Private Real _x Private Real y Public Module set_x(Real value) Set _X = value End Module Public Module set_y(Real value) Set y = value End Module Public Function get_x() Return _X End Module Public Function get_y() Return y End Module Public Module add(Coordinate c) Set _X = _X + C.get_x) Set y = y + c.get_y() End Module End Class Module main() Declare Coordinate ci - New Coordinate() Declare Coordinate c2 - New Coordinate()...

  • What will the following pseudocode program display

    What will the following pseudocode program display? Module main( ) Declare Integer x = 1 Declare Real y = 3.4 Display x, " ", y Call changeUs(x, y) Display x, " ", y End Module Module changeUs(Integer a, Real b) { Set a = 0 Set b = 0 Display a, " ", b }

  • I am supposed to a pseudocode function named max that accepts two integer values as arguments...

    I am supposed to a pseudocode function named max that accepts two integer values as arguments and returns the value that is greater of the two. Use the function in a program that prompts the user to enter two integer values. The program should display the value that is greater of the two. Is everything correct and complete? //Pseudocode //This function takes two integers as parameters: x and y Begin : Max(x,y) If(x>y) then MAX=x Else MAX=y End if Return...

  • A perfect number is a positive integer that is equal to the sum of its (proper)...

    A perfect number is a positive integer that is equal to the sum of its (proper) positive divisors, including 1 but excluding itself. A divisor of a number is one which divides the number evenly (i.e., without a remainder). For example, consider number 6. Its divisors are 1, 2, 3, and 6. Since we do not include number itself, we only have 1, 2, and 3. Because the sum of these divisors of 6 is 6, i.e., 1 + 2...

  • A positive integer n is “perfect” if the sum of its positive factors, excluding itself, equals...

    A positive integer n is “perfect” if the sum of its positive factors, excluding itself, equals n.  Write a perfect function in Haskell that takes a single integer argument and returns the list of all perfect numbers up to that argument. Report all of the perfect numbers up to 1000 (i.e. call 1000)

  • An integer is said to be a perfect number if the sum of its divisors, including...

    An integer is said to be a perfect number if the sum of its divisors, including 1(but not the number itself), is equal to the number. For example, 6 is a perfect number because 6 = 1+2+3. A) Write a function numPerfect( number ) that returns true when the number is a perfect number, false when it is not.        B) Write a C# console program that calls the function in A) to determine and print all the perfect numbers...

  • Write the Flowchart for the following programming problem based on the pseudocode below. Last year, a...

    Write the Flowchart for the following programming problem based on the pseudocode below. Last year, a local college implemented rooftop gardens as a way to promote energy efficiency and save money. Write a program that will allow the user to enter the energy bills from January to December for the year prior to going green. Next, allow the user to enter the energy bills from January to December of the past year after going green. The program should calculate the...

  • Below is a pseudocode for a function that finds the integer 5 in the 3 element integer array. The...

    Below is a pseudocode for a function that finds the integer 5 in the 3 element integer array. The number 5 is in the array, but it is not known where it is. The Find5 function returns it’s seat number. Find5 (A[1..3]) found = false while( not found ) i = random(1, 3) if A[i] == 5 then found = true return i The function random (i, j) returns the integer of the closed range [i..j] with equal probability for...

  • Look at this partial class definition, and then answer questions a - b below: Class Book...

    Look at this partial class definition, and then answer questions a - b below: Class Book    Private String title    Private String author    Private String publisher    Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant    Public Module message()       Display "I'm a plant."    End Module...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT