Question

No subject Start count 1 Tes Read num Print count count 1 End

what does this algorithm do?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The program initially takes two variables sum and count with values 0 and 9 respectively

then starts a loop in which it checks the for the condition if the count value is greater than 0 or not

The condition gets true, and the program enters the loop,

it reads an input from user and stores it in a variable num

then it adds the value read from the user to the value of sum (which was initially 0)

then it decreases the value of count by 1

this loop continues till count value is not equal to zero

when the value of count reaches to zero the if condition fails and the control passes to else block

Here, division by 9 is performed on the calculated sum and stored in the variable x.

Then the value is printed and the program ends

Add a comment
Know the answer?
Add Answer to:
what does this algorithm do? No subject Start count 1 Tes Read num Print count count...
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
  • Compare the algorithm below: Algorithm 1 for i= 0 to i = 4 get the num[i]...

    Compare the algorithm below: Algorithm 1 for i= 0 to i = 4 get the num[i] sum = sum + num[i] Average = sum / 5 Print sum Print average Algorithm 2 for i= 0 to i = 4 get the num[i] for i= 0 to i = 4 sum = sum + num[i] Average = sum / 5 Print sum Print average Calculate the complexity of the algorithm. Choose the most efficient algorithm, explain your choice.

  • What is the output of the following C++ code? int count = 1; int num =...

    What is the output of the following C++ code? int count = 1; int num = 25; while (count < 25) { num--; count++; } cout << count « " " « num << endl i 25 1 0 24 1 0 25 0 0 24 0 In this while loop statement, while (counter < 10), where counter is an int variable. Which statement below is an equivalent way to write this while statement? while (10 < counter) while (9...

  • Let A[1..n] be an array with n elements. Consider the Count-Occurrence algorithm with the pseudocode below....

    Let A[1..n] be an array with n elements. Consider the Count-Occurrence algorithm with the pseudocode below. Count-Occurrence(A, n, k). count 0 for j = 1 to n if A[j] ==k count = count+1 print count Which of the following is the correct loop invariant for the for loop? At the start of each iteration jof the for loop, count represents the number of times that k occurs in the subarray A[1.j]. At the start of each iteration of the for...

  • What C++ data type should be returned from the function/method? // Start //     Declarations //       num amount //       num...

    What C++ data type should be returned from the function/method? // Start //     Declarations //       num amount //       num newAmount //       num interestRate //     output "Please enter the dollar amount.   " //     input amount //     output "Please enter the interest rate(e.g., nine percet should be entered as 9.0).   " //     input interestRate //     newAmount = FutureValue(amount,interestRate) //     output "The new dollar amount is ", newAmount // Stop // // // // num FutureValue(num initialAmount, num interestRate) //     Declarations //       num finalAmount //     finalAmount = (1 + interestRate/100) * initialAmount // return finalAmount

  • 4. (Syntax-directed translation) Assume that a bottom-up parser is used for the following grammar. follows? (1...

    4. (Syntax-directed translation) Assume that a bottom-up parser is used for the following grammar. follows? (1 2 3) (4 5 678 9) $. What does it print when the input is as 1 Start ListeS Iparen Operands rparen PRINT(Count) 2 List.l 3243 I num 3 tuit 4 Operands Operands List count-count+1 I List 5 count-1 4. (Syntax-directed translation) Assume that a bottom-up parser is used for the following grammar. follows? (1 2 3) (4 5 678 9) $. What does...

  • (V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a...

    (V). Given the following algorithm, answer relevant questions. Algorithm 1 An algorithm 1: procedure WHATISTHIS(21,22,...,n: a list of n integers) for i = 2 to n do c= j=i-1 while (j > 0) do if ra; then break end if 4j+1 = a; j= j-1 end while j+1 = 1 end for 14: return 0.02. 1, 15: end procedure Answer the following questions: (1) Run the algorithm with input (41, 02, 03, 04) = (3, 0, 1,6). Record the values...

  • Write a python program write a function numDigits(num) which counts the digits in int num. Answer...

    Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...

  • Count the number of assignments and comparisons in this algorithms. a) Algorithm Loop1(n): p+ 1 for...

    Count the number of assignments and comparisons in this algorithms. a) Algorithm Loop1(n): p+ 1 for i = 1 to n do ppi b) Algorithm Loop2(n): SO for i = 1 to n do for j = 1 to i do Sesti

  • - 4. (Syntax-directed translation) Assume that a bottom-up parser is used for the following grammar. What...

    - 4. (Syntax-directed translation) Assume that a bottom-up parser is used for the following grammar. What does it print when the input is as follows? ( (1 2 3) (4 5 6 7 8 9) ) $. 1 Start Lista $ 2 Lista! Iparen Operands, paren PRINT(count) Hint 3 2 4 3 3 num 4 Operands-Operands List count count +1 5 List count1

  • Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word)...

    Problem 1 1 def modify(word.ch). word == word + ch return word print('new word is', word) To run the function modify() defined above, we make the following call: result = modify('course', 's') Find and fix the errors in the function definition, lines (1) to (4), such that after the call is executed: • Variable result has the value 'courses' • 'new word is courses' is printed out. For each error found and fixed, you must indicate the following: • line...

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