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
  • Please select the output: main         declare X as integer, Y as integer                        &nbsp

    Please select the output: main         declare X as integer, Y as integer                                 set x=1                                 set y=2                                 call sub(x, y)                                 write x                                 write y End program Subprogram sub( integer Num1 as ref, Integer Mum2 as reference)                                                              declare x as integer                                                 set Num1 = 3                                                 set Num2 = 4                                                 set x= 5                                                 write x end subprogram           Please select one:      5/42, 5/34, 5/32, 5/24 What is the output of this...

  • 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...

  • Write the pseudocode below as a working Python program. Take a screenshot of your code and...

    Write the pseudocode below as a working Python program. Take a screenshot of your code and output and paste into your answer document. User input of ‘y’ or ‘Y’ should cause the loop to continue.    // Constant for the commission rate    // Declare as a global variable    Constant Real COMMISSION_RATE = 0.10     Module main()        // Local variable         Declare String keepGoing = "y"         // Calculate as many commissions         // as needed.         While...

  • draw the flowchart for : 1. PseudoCode algorithm: Declare variable of type float a,b, sum=0 Print...

    draw the flowchart for : 1. PseudoCode algorithm: Declare variable of type float a,b, sum=0 Print "Enter 2 float numbers" input a and b; compute sum=a+b; print sum 2. Declare variable of type integer a, b, max Print "Enter 2 integer numbers" input a and b; if a>b max=a; else max=b; print "Maximum of two is ", max;

  • 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...

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