recategorized by
4,320 views
5 votes
5 votes

Consider the following C code segment:

#include <stdio.h>
main()
{
    int i, j, x;
    scanf("%d", &x);
    i=1; j=1;
    while (i<10) {
            j =j*i;
            i= i+1;
            if(i==x) break;
        }
}

For the program fragment above, which of the following statements about the variables i and j must be true after execution of this program? [ !(exclamation) sign denotes factorial in the answer]

  1. $(j=(x-1)!)$ $\wedge$ $(i$$\geq x$$)$
  2. $(j=9!)$ $\wedge$  $(j=10)$
  3. $((j=10!)$ $\wedge$ $(i=10))$ $\vee$ $((j=(x-1)!)$ $\wedge$ $(i=x))$
  4. $(j=9!)$ $\wedge$$ (i\geqslant$$10$)) $\vee$ $((j=(x-1)!) $$\wedge$$ (i=x))$
recategorized by

1 Answer

Best answer
8 votes
8 votes
option D is correct

when value of x>= 10 then value of j will be 9! because condition of while loop is (i<10) .so i will run till 9 and j value will be computed as 9!

and if x<10 then loop will terminate when i will be incremented up to x.So that time j value will be computed as (x-1)!
selected by
Answer:

Related questions

5 votes
5 votes
4 answers
1
Arjun asked Apr 22, 2018
4,217 views
Consider the following C program:main() { float sum= 0.0, j=1.0,i=2.0; while(i/j>0.001){ j=j+1; sum=sum+i/j; printf("%f/n", sum); } }$0$ - $9$ lines of output$10$ - $19$ ...
5 votes
5 votes
2 answers
2
Arjun asked Apr 22, 2018
8,442 views
Consider the following program{ int x=1; printf("%d",(*char(char*)&x)); }Assuming required header files are included and if the machine in which this program is executed ...
5 votes
5 votes
3 answers
3
Arjun asked Apr 22, 2018
5,573 views
Consider the following declaration :structaddr { char city[10]; char street[30]; int pin; }; struct { char name[30]; int gender; struct addr locate; } person, *kd = &pers...
1 votes
1 votes
2 answers
4