Computer Science, asked by parijain20151071, 1 month ago

what will be the new value of k from : k=(k%3==0)? (k*3) :(k+3) if k=15 (ii) k =0
answer me fast​

Answers

Answered by abhyas29
1

Answer:

k = 15

45

k = 0

0

Explanation:

The expression, (k%3==0)? (k*3) :(k+3), checks if k is divisible by 3 or not, if yes then evaluate to (k * 3) else evaluate to (k + 3)

15 is divisible by 3, so k = 15 * 3

0 is also divisible by 3, because when you divide 0 by 3 you get 0 remainder which is the definition of divisibility, so k = 0

Answered by BrainlyProgrammer
4

Answer:

The given expression is a ternary operator

 \tt \:  \orange{k=(k \%3==0)?(k*3):(k+3);}

Solution:-

  • when k=15

 \tt \:  \orange{k=(k \%3==0)?(k*3):(k+3);} \\  :  \implies \: (15 \%3==0)?(15*3):(15+3) \\  :  \implies \: (true)?(45):(18)

Since the condition is true, k will store 45 as it's value.

  • when k=0

 \tt \:  \orange{k=(k \%3==0)?(k*3):(k+3);} \\  :  \implies \: (0 \%3==0)?(0*3):(0+3) \\  :  \implies \: (true)?(45):(18)

Here, again the condition is true, k will store 0 as it's new value

Final Answer:-

  • When k=15,

k=45

  • When k=0,

k=0

Similar questions