55.2k views
5 votes
Write an expression that, given a positive integer n, computes a new integer in which the units and tens digits have swapped places.

A. n+90

B. 10n+n/10

C.10n+n%10/10

D.10(n%10)+n/10


User Dividius
by
8.2k points

1 Answer

2 votes

Final answer:

The correct expression to swap the units and tens digits of a positive integer n is: 10(n%10) + n/10.

Step-by-step explanation:

The correct expression to swap the units and tens digits of a positive integer n is: 10(n%10) + n/10.

Let's break down the expression step by step:

  1. n%10 is used to get the remainder when n is divided by 10. This gives us the units digit of n.
  2. 10(n%10) multiplies the units digit by 10 to make it the new tens digit.
  3. n/10 is used to get rid of the original tens digit. It performs integer division to remove the units digit.
  4. Finally, 10(n%10) + n/10 adds the new tens digit (10(n%10)) and the removed units digit (n/10) to form the new integer.

User Zenexer
by
8.9k points