Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you explain how to find the answers to 1 and 4? I don't understand how to apply the hinted formula. ( begin{array}{ll}text { //
Can you explain how to find the answers to 1 and 4? I don't understand how to apply the hinted formula.
\( \begin{array}{ll}\text { // Prerequisite: } n>=0 . & \\ \text { int twiddle_thumbs(int } n)\{ & \\ \quad \text { int } i=0 ; & / / \text { Line } 1 \\ \quad \text { int result }=8 ; & / / \text { Line } 2 \\ \text { int } p=10 ; & / / \text { Line } 3 \\ \text { while }(pi,p, and n for this problem. As you analyse this, you will probably want to write out a formula for result first using or notation! Note that i is there just for convenience to help you count the number of times we've gone through the loop! Now, answer the following questions about the code: 1. Finish this to make a (correct and descriptive) invariant on result: Just before each iteration of the loop, expressed in terms of i, result is equal to exactly: 5i2+5i+8 Hint: You may find it helpful to remember that k=1jk=2j(j+1). 4. In terms of n, the exact final value of result is: 20n2+10n+8Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
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