Question

In: Computer Science

(need in frame -c) In the given code, Will all the assert statements prove true? Give...

(need in frame -c)
In the given code, Will all the assert statements prove true? Give reason for proved
true or false for each assert statement. [3 M] [CO2]
int main(){
int i = 1;
int x = 33;
/*@
loop invariant 1 <= i <= 19;
loop assigns i;
loop variant 20 - i;
*/
//@assert i == 1;
while(i < 20){
++i;
if(i == 20) break ;
}
//@assert i == 20;
//@assert x == 33;
}

frama-c is a acsl language..

Solutions

Expert Solution

Answer

In the given code all the assert statements will be true.

i. Initially the integer variable 'i' is assigned with 1, and before entering the while loop, the assert statement checks whether 'i' is 1 or not. The variable 'i' will be 1 at this particular statement, hence this assert will prove true.

ii. Inside the while loop the variable 'i' is getting incremented until it reaches 20, when the value of 'i' becomes 20, the control comes out of the while loop. Immediately after the control comes out of the while loop there is a assert statement which checks whether the variable 'i' contains 20 or not. The variable 'i' will be 20 at this particular statement, hence this assert will prove true.

iii. The last assert statement checks whether the value of 'x' is 33 or not. The value of 'x' is initially initialized with 33 and is never modified after that. Hence this assertion will prove true.


Related Solutions

NOTE- If it is true, you need to prove it and If it is false, give...
NOTE- If it is true, you need to prove it and If it is false, give a counterexample f : [a, b] → R is continuous and in the open interval (a,b) differentiable. a) If f(a) ≥ f(b), then exists a ξ ∈ (a,b) with f′(ξ) ≤ 0.(TRUE or FALSE?) b) If f is reversable, then f −1 differentiable. (TRUE or FALSE?) c) If f ′ is limited, then f is lipschitz. (TRUE or FALSE?)
NOTE- If it is true, you need to prove it and If it is false, give...
NOTE- If it is true, you need to prove it and If it is false, give a counterexample f : [a, b] → R is continuous and in the open interval (a,b) differentiable. a) If f(a) ≥ f(b), then exists a ξ ∈ (a,b) with f′(ξ) ≤ 0. (TRUE or FALSE?) b) If f is reversable, then f −1 differentiable. (TRUE or FALSE?) c) f is constant ⇐⇒ ∀x∈(a,b): f′(x)=0 (TRUE or FALSE?)
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c...
C Code! I need all of the \*TODO*\ sections of this code completed. For this dictionary.c program, you should end up with a simple English-French and French-English dictionary with a couple of about 350 words(I've provided 5 of each don't worry about this part). I just need a way to look up a word in a sorted array. You simply need to find a way to identify at which index i a certain word appears in an array of words...
1. Determine if the following statements are true or false. If a statement is true, prove...
1. Determine if the following statements are true or false. If a statement is true, prove it in general, If a statement is false, provide a specific counterexample. Let V and W be finite-dimensional vector spaces over field F, and let φ: V → W be a linear transformation. A) If φ is injective, then dim(V) ≤ dim(W). B) If dim(V) ≤ dim(W), then φ is injective. C) If φ is surjective, then dim(V) ≥ dim(W). D) If dim(V) ≥...
Which of the following statements are true for the photoelectric effect? Give all the correct answers,...
Which of the following statements are true for the photoelectric effect? Give all the correct answers, e.g., enter ABC. The maximum kinetic energy of the ejected electrons is proportional to the velocity of the incoming photons. The maximum kinetic energy of the ejected electrons increases linearly with the frequency of the incident light. The frequency of the incoming photons must be larger than a certain minimum value in order to eject electrons from the metal. The maximum kinetic energy of...
Several statements regarding MAC protocols are give below. Indicate the true statements. All packets are assumed...
Several statements regarding MAC protocols are give below. Indicate the true statements. All packets are assumed to be of fixed size and take exactly one unit of time to transmit.    1) In Ethernet protocol, nodes that encountered collision to their transmissions back off for random amount of times based on their frame types. 2) In Aloha protocol, nodes transmit when they sense the channel to be idle. 3) In slotted Aloha, a node's transmission is successful if there is...
Which of these statements about deadlock are true? (list all that are true.) a. If all...
Which of these statements about deadlock are true? (list all that are true.) a. If all transactions use two-phase locking, they cannot deadlock. b. Once two transactions deadlock, one of them must be aborted to maintain correctness. c. Systems that support update locks (S, X and U modes) cannot deadlock. d. Validation based concurrency control schemes cannot deadlock.
this is a python code that i need to covert to C++ code...is this possible? if...
this is a python code that i need to covert to C++ code...is this possible? if so, can you please convert this pythin code to C++? def main(): endProgram = 'no' print while endProgram == 'no': print # declare variables notGreenCost = [0] * 12 goneGreenCost = [0] * 12 savings = [0] * 12 months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] getNotGreen(notGreenCost, months) getGoneGreen(goneGreenCost, months) energySaved(notGreenCost, goneGreenCost, savings) displayInfo(notGreenCost, goneGreenCost, savings, months)...
c# code working but output not right, I need to output all numbers like : Prime...
c# code working but output not right, I need to output all numbers like : Prime factors of 4 are: 2 x 2 here is just 2 Prime factors of 7 are: 7 Prime factors of 30 are: 2 x 3 x 5 Prime factors of 40 are: 2 x 2 x 2 x 5 here is just 2,5 Prime factors of 50 are: 2 x 5 x 5 here is just 2,5 1) How I can fix it 2)I...
All of the following statements are true except:
  All of the following statements are true except: a. A portfolio may contain multiple programs and projects. b. A project manager has the discretion to make trade-offs in regard to which programs to pursue. c. A program manager has the discretion to make trade-offs in regard to which projects to pursue. d. Projects have a finite timeline, while programs may exist as long as the parent organization does. Which of the following is a financial analysis tool that an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT