2. Write and verify a program that computes the sum of the squares of the n...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
2. Write and verify a program that computes the sum of the squares of the n smallest positive odd integers. For example, when n is 4, the sum should be 1 + 9 + 25 + 49 == 84. Here is the specification: Declarative interface: const int n; /*n is the number of squares (input) */ int sum; /* the sum is stored in this variable */ Pre-condition: ASSERT(n >= 1 ) Post-condition: ASSERT ( sum === (2*1+1)*(2*1+1) ) The program should use a while-loop and standard arithmetic operations. Select a loop invariant and give a complete proof tableau for the program (including all the intermediate assertions). Also make an argument for termination. 2. Write and verify a program that computes the sum of the squares of the n smallest positive odd integers. For example, when n is 4, the sum should be 1 + 9 + 25 + 49 == 84. Here is the specification: Declarative interface: const int n; /*n is the number of squares (input) */ int sum; /* the sum is stored in this variable */ Pre-condition: ASSERT(n >= 1 ) Post-condition: ASSERT ( sum === (2*1+1)*(2*1+1) ) The program should use a while-loop and standard arithmetic operations. Select a loop invariant and give a complete proof tableau for the program (including all the intermediate assertions). Also make an argument for termination.
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Let r and s be solutions to the quadratic equation x 2 b x + c = 0. For n N, define d0 = 0 d1 = r s dn = b dn1 c dn2 (n 2) Prove that dn = r n s n for all n N. [4 marks] (b) Recall that a commutative...
-
Controlling Program Flow w/i an ATM Using selection statements & loops to complete the following: Validate the user's PIN -- only allow them to attempt three (3) times before ending the program If...
-
The doctrine of respondeat superior should be modified to make agents solely liable for their tortious (wrongful) acts committed within the scope of employment. Explain
-
9 The company has identified the following information about its overhead activity pools and the two product lines: Activity Pools Materials handling Quality control Machine maintenance Required:...
-
A study of National Football League (NFL) retirees, ages 50 and older, found that 62.4% have arthritis. You randomly select 75 NFL retirees who are at least 50 years old and ask them whether they...
-
Suppose you hold two series of options, both NQOs. Because of a big promotion, you expect your tax rate to increase from a current 31% to 39.6%. The current stock price is $70. The first set of...
-
When Liam Cote decided to help his cousin Felix Cote turn around his business, he had no idea that things were as bad as they were. Liam knew that the bank's loan was coming due and the company could...
-
The production manager at a factory manufacturing four types of light fittings (A, B, C and D) on an automated machine is fixing the schedule for the next week on this machine. HEIJUNKA SCHEDULING OF...
-
Using Table 11-1, calculate the compound amount and compound interest (in $) for the investment. (Round your answers to the nearest cent.) Time Nominal Interest Principal Period (years) Rate (%)...
-
The DoGood Funds approach to the aerospace and defense industry is best described as: A. positive screening. B. negative screening. C. thematic investing. Three years ago, the Albright Investment...
-
Based on what the IC considers important for equity-related strategies, which strategy should Mukilteo most likely avoid? A. Long/short equity B. Equity market neutral C. Dedicated short selling and...
-
Which of the IC members statements regarding hedge fund strategies is incorrect? A. Statement 1 B. Statement 2 C. Statement 3 Snohomish Mukilteo is a portfolio analyst for the Puyallup-Wenatchee...
-
Which of the following notes about the DoGood Fund is correct? A. Only Note 2 B. Only Note 3 C. Both Note 2 and Note 3 Three years ago, the Albright Investment Management Company (Albright) added...
-
The government bond strategy that Mukilteo considers is best described as a: A. carry trade. B. yield curve trade. C. long/short credit trade. Snohomish Mukilteo is a portfolio analyst for the...
-
An engineer wishing to obtain the speed characteristics on a bypass around her city at a confidence level of 95%, and an acceptable limit of 1.0 mi/h collected a total of 130 spot speed samples and...
-
The first law of thermodynamics is sometimes whimsically stated as, You cant get something for nothing, and the second law as, You cant even break even. Explain how these statements could be...
-
Scott Butterfield is self-employed as a CPA. He uses the cash method of accounting, and his Social Security number is 644-47-7833. His principal business code is 541211. Scott's CPA practice is...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family. The Incisors own a rental beach house in Hawaii. The beach house was rented for the full year during 2012...
-
Cedar Corporation has an S corporation election in effect. During the 2012 calendar tax year, the corporation had ordinary taxable income of $200,000, and on January 15, 2012, the corporation paid...
-
What are the various forms of virtual communication used in modern organizations?
-
What are the types of interpersonal communication?
-
How does one choose between communication methods and handle barriers to effective communication?
Study smarter with the SolutionInn App