in Programming edited by
149 views
2 votes
2 votes

Choose the correct operators to fill in the blanks:

int i,j,k;
i=1;j=2;k=3;
printf("%d",i___5___j___2____k);

Output is: $2$

 

  1. +  % –  +
  2. *  /  –  +
  3. +  %  +  /
  4. * % –  /
in Programming edited by
by
149 views

1 Answer

2 votes
2 votes
Best answer



precedence

*,/,%  L->R

+,-    L->R

 

  • A) i+5%j-2+k

i+1-2+k

= 2-2+k

= 0+k
= 3

  • B) i * 5 / j - 2 + k

5/j-2+k
= 2-2+k
= 0+k
= 3

  • C) i +5% j +2 /k

i+1+2/k
= i+1+0
= 2

  • D) i * 5% j -2/ k

i*5 %2 -2/k
=5%2 - 2/k
= 1 - 2/3

= 1 - 0

= 1

So, answer is option C .

selected by

4 Comments

@jai

Sorry, output would be 2 , can you check it now ?
1
1
@Bikram  sir , still i am getting 2 in option C as well as in D
1
1
@jai

For option D

* % - /

i * 5% j- 2 /k

= (i * 5) %j - 2 / k

=( (1 * 5 ) % 2 ) - (2 /k )

= (5 % 2 ) - (2/k)

= 1 - ( 2/3)

= 1 - 0

= 1

so for option D we are getting 1 .

Hence for only option C , we get value 2 .
2
2
sir why you putting (2/3) to zero ??
0
0
Answer:

Related questions