I'm struggling to come up with a loop invariant for the following piece of code:
OddNumber(n)
- a = 2
- for i = 1 to n do
-
a = a * i
- return a+1
Now, I want to find a loop invariant which is correct before entering the for-loop in l.2. My idea was that a = the product from k=1 to i-1 multiplied with 2, however, I have trouble involving the 1 added in the end.