Lesson 2
The Basic Elements
Chapter 10: Applied problem solving
Linear indices to subscripts (3D)
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).
Your program should read in the following integer inputs from the user:
- The length of dimension 1
- The length of dimension 2
- The length of dimension 3
- 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)