34.1k views
2 votes
Given three already declared int variables, i, j, and temp.

A. Swap i and j values using temp
B. Add i and j values and store in temp
C. Multiply i and j values and store in temp
D. Initialize temp to the average of i and j

1 Answer

2 votes

Final answer:

To manipulate the values of i and j using a third variable temp, you can use different operations such as swapping, addition, multiplication, and calculating the average.

Step-by-step explanation:

Given three already declared int variables, i, j, and temp:

  1. To swap the values of i and j, you can assign the value of i to temp, then assign the value of j to i, and finally assign the value of temp to j. This will swap their values.
  2. To add the values of i and j and store the result in temp, you can simply use the addition operator: temp = i + j.
  3. To multiply the values of i and j and store the result in temp, you can use the multiplication operator: temp = i * j.
  4. To initialize temp to the average of i and j, you can calculate the average by adding i and j and dividing by 2: temp = (i + j) / 2.
User Jaswant Singh
by
8.8k points