CrazyEngineers
  • Write a C Program

    Updated: Oct 22, 2024
    Views: 1.1K
    Consider the following program fragment:
    1. i = 1; sum=0;
    2. while (i <= n) do
    begin
    3. sum = sum + a;
    4. i = i + 1;
    end
    Let
    A represent the initialization in line 1
    B represent the action within the loop in line 3
    I represent the increment in line 4
    T represent the test implied by line 2
    Which of the following regular expressions represents all possible sequences of steps
    taken by this program? Justify your answer.
    I. A(TBI)*
    II. AT+B*I*
    III. AT(BIT)+
    IV. AT(BIT)*
    V. A(TBI)+
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • nareshkumar6539

    MemberApr 22, 2012

    Answer is AT(BIT)*
    first of all value will be initialized(A),after that condition will be checked(AT),condition can be TRUE or FALSE,if condition is false it will never enter into loop.If condition is true it will enter into loop first sum will be added after that i value incremented after that it again check for condition if true it enter into loop otherwise come out from the loop.
    Note:-
    In regular expressions * means 0 or more(0,1,2,---infinity)
    + means 1 or more(1,2,3---infinity)
    I. is wrong because condition is not checked if * takes 0 then the expression simply A condition must be checked.First it must be checked the condition(AT)
    II is wrong because that expression doesn`t show after entering the loop performing 2 steps we have to again check the condition it is not showing
    III is wrong because it is not showing expression for first itself condition is false it doecn`t enter into loop but in this even condition false also it will enter into the loop
    V is wrong because of above reason only
    Are you sure? This action cannot be undone.
    Cancel
  • Manashree Thokal

    MemberApr 23, 2012

    IV. AT(BIT)*

    A is definitely executed.
    Even T is. The condition is definitely checked.
    B is always followed by I, as its in a loop. Control goes to T again.
    It is a closure as the entry in loop depends on value of n. If i is not <= n, BIT will be empty.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register