11. a student is creating an algorithm to display the distance between the numbers num1 and num2 on a number…

11. a student is creating an algorithm to display the distance between the numbers num1 and num2 on a number - line. the following table shows the distance for several different values.\n| value of num1 | value of num2 | distance between num1 and num2 |\n| ---- | ---- | ---- |\n| 5 | 2 | 3 |\n| 1 | 8 | 7 |\n| -3 | 4 | 7 |\nwhich of the following algorithms displays the correct distance for all possible values of num1 and num2?\n(a) step 1: add num1 and num2 and store the result in the variable sum.\nstep 2: take the absolute value of sum and display the result.\n(b) step 1: subtract num1 from num2 and store the result in the variable diff.\nstep 2: take the absolute value of diff and display the result.\n(c) step 1: take the absolute value of num1 and store it in the variable absnum1.\nstep 2: take the absolute value of num2 and store it in the variable absnum2.\nstep 3: add absnum1 and absnum2 and display the result.\n(d) step 1: take the absolute value of num1 and store it in the variable absnum1.\nstep 2: take the absolute value of num2 and store it in the variable absnum2.\nstep 3: subtract absnum1 from absnum2 and display the result.

11. a student is creating an algorithm to display the distance between the numbers num1 and num2 on a number - line. the following table shows the distance for several different values.\n| value of num1 | value of num2 | distance between num1 and num2 |\n| ---- | ---- | ---- |\n| 5 | 2 | 3 |\n| 1 | 8 | 7 |\n| -3 | 4 | 7 |\nwhich of the following algorithms displays the correct distance for all possible values of num1 and num2?\n(a) step 1: add num1 and num2 and store the result in the variable sum.\nstep 2: take the absolute value of sum and display the result.\n(b) step 1: subtract num1 from num2 and store the result in the variable diff.\nstep 2: take the absolute value of diff and display the result.\n(c) step 1: take the absolute value of num1 and store it in the variable absnum1.\nstep 2: take the absolute value of num2 and store it in the variable absnum2.\nstep 3: add absnum1 and absnum2 and display the result.\n(d) step 1: take the absolute value of num1 and store it in the variable absnum1.\nstep 2: take the absolute value of num2 and store it in the variable absnum2.\nstep 3: subtract absnum1 from absnum2 and display the result.

Answer

Explanation:

Step1: Recall distance formula on number - line

The distance $d$ between two numbers $a$ and $b$ on a number - line is given by $d=\vert a - b\vert$. In terms of num1 and num2, the distance between num1 and num2 is $\vert num2 - num1\vert$.

Step2: Analyze option A

Adding num1 and num2 and taking the absolute - value ($\vert num1 + num2\vert$) does not give the distance between them on the number - line. For example, if num1 = 5 and num2 = 2, $\vert5 + 2\vert=7\neq3$.

Step3: Analyze option B

Subtracting num1 from num2 gives diff = num2 - num1, and then taking the absolute value $\vert num2 - num1\vert$ gives the correct distance between num1 and num2 on the number - line. For num1 = 5, num2 = 2, $\vert2 - 5\vert=\vert-3\vert = 3$; for num1 = 1, num2 = 8, $\vert8 - 1\vert = 7$; for num1=-3, num2 = 4, $\vert4-(-3)\vert=\vert4 + 3\vert = 7$.

Step4: Analyze option C

Taking the absolute values of num1 and num2 separately and then adding them ($\vert num1\vert+\vert num2\vert$) does not give the distance between them on the number - line. For example, if num1=-3 and num2 = 4, $\vert-3\vert+\vert4\vert=3 + 4=7$, but this is not the correct way to calculate the distance between them on the number - line.

Step5: Analyze option D

Taking the absolute values of num1 and num2 separately and then subtracting ($\vert num2\vert-\vert num1\vert$) does not give the distance between them on the number - line. For example, if num1=-3 and num2 = 4, $\vert4\vert-\vert-3\vert=4 - 3 = 1\neq7$.

Answer:

B. Subtract num1 from num2 and store the result in the variable diff. Take the absolute value of diff and display the result.