Question: Question 1 . ( 4 0 pts . ) Consider the loop in sumN ( ) . sumN ( ) requires n > 0 &&
Question pts Consider the loop in sumN sumN requires n && n ie n is an odd positive integer and
returns the sum of odd integers through n For example, sumN
precondition: n n
int sumNint n
int k ;
int sum ;
LI: sum k k k n
while k n
sum sum k;
k k ;
return sum;
postcondition: sum n
Given the loop invariant sum k k k n show that the loop invariant is true for the base
case before the loop executes. pts
Use induction to show that the loop invariant holds for the general case. That is assume it holds after some iteration m
and show that it holds after iteration m pts
Show that at exit, the loop invariant and the exit condition imply the postcondition. pts
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
