113k views
2 votes
Given the following code:

if (n==2)
{
k-= 2;
}
else if (n==3)
{
k-=3;
}

can be rewritten as if ()
{
;
}

where < condition > and < assignment statement > are chosen so that the rewritten code performs the same task as the original code. Assume that both n and k are integer variables. Which of the following could be used as < condition >?

I. (n == 2) || (n == 3)
II. (n == 2) && (n == 3)
III. (n >= 2) && (n <= 3)

a. 1 only
b. 2 only
c. 3 only
d. 1 and 3 only
e. 2 and 3 only

User FixMaker
by
4.0k points

1 Answer

4 votes

Answer:

a. 1 only ie

I. (n == 2) || (n == 3)

Step-by-step explanation:

An integer is a number that can be written without a fractional component. For example, 21, 4, 0, and −2048 are integers, while 9.75, 5+, and √2 are not. The set of integers consists of zero, the positive natural numbers, also called whole numbers or counting numbers, and their additive inverses.

The answer is I. (n == 2) || (n == 3)

User Raul Cuth
by
4.0k points