This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 10: Applied problem solving

Linear indices to subscripts (3D)

face Josiah Wang

If case you are feeling pumped up, here is an optional final final bonus challenge! Try implementing the 3D problem in the inverse direction, that is, s \rightarrow (x_1, x_2, x_3).

Convert linear indices to 3D subscripts

Your program should read in the following integer inputs from the user:

  1. The length of dimension 1
  2. The length of dimension 2
  3. The length of dimension 3
  4. An index

The program should output the 3D subscript (x_1, x_2, x_3) corresponding to the given index.

Sample run #1:

Enter dimension 1 length: 2
Enter dimension 2 length: 3
Enter dimension 3 length: 4
Enter index: 9
(0, 2, 1)

Sample run #2:

Enter dimension 1 length: 6
Enter dimension 2 length: 2
Enter dimension 3 length: 5
Enter index: 59
(5, 1, 4)