3D multiplication table
This is a 3D multiplication table. I took a 3D array and added header fields. You take the five sets and stack them in order. You get 0 to 3 on X,Y and Z axis. The tables create a 3D multiplication cube.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chapter73DArray
{
//create a multiplication table for 0 to 5
class Program
{
static void Main(string[] args)
{
int z1 = 5;
int z2 = 5;
int z3 = 5;
int[,,] array = new int[z1, z2, z3];
int x;
int y;
int z;
int s;
//generate the X,Y, and Z rows
for (x = 1; x < z1; x++)
{
array[x, 0, 0] = x - 1;
};
for (y = 1; y < z2; y++)
{
array[0, y, 0] = y - 1;
}
for (z = 1; z < z3; z++)
{
array[0, 0, z] = z - 1;
}
//Calculate the table
// (0, 0, 0) should be 0 in corner
// Start of each count is
// (1, 0, 0) is X at 0
// (0, 1, 0) is Y at 0
// (0, 0, 1) is Z at 0
for (x = 1; x < z1; x++)
{
for (y = 1; y < z2; y++)
{
for (z=1; z < z3; z++)
{
array[x, y, z] = (array[0, 0, z] * array[0, y, 0] * array[x, 0, 0]);
}
}
}
s = array[2, 2, 2];
Console.WriteLine(s.ToString("000") + " ");
Console.WriteLine();
s = array[3, 3, 1];
Console.WriteLine(s.ToString("000") + " ");
Console.WriteLine();
//prints the array
for (x = 0; x < z1; x++)
{
for (y = 0; y < z2; y++)
{
for (z = 0; z < z3; z++)
{
s = array[x, y, z];
Console.Write(s.ToString("000") + " ");
}
Console.WriteLine();
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Set 1: Red top column and first row, are X and Y values 0 to 3. Cut each of the 5 arrays and place in order on top of each other it forms a 3D multiplication table from 0 to 3. Starting second array to fifth array, left upper corner is Z = 0 to 3. Second column and second row starts at 0. Last column and row = 3. Top row and first column are just Z values on sets 2 to 5. It forms a cube with header rows and columns.
000 000 001 002 003
000 000 000 000 000
001 000 000 000 000
002 000 000 000 000
003 000 000 000 000
000 000 000 000 000
000 000 000 000 000
000 000 000 000 000
000 000 000 000 000
000 000 000 000 000
001 000 000 000 000
000 000 000 000 000
000 000 001 002 003
000 000 002 004 006
000 000 003 006 009
002 000 000 000 000
000 000 000 000 000
000 000 002 004 006
000 000 004 008 012
000 000 006 012 018
003 000 000 000 000
000 000 000 000 000
000 000 003 006 009
000 000 006 012 018
000 000 009 018 027
Red 27 is 3 x 3 x 3. X, Y and Z axis goes 0 to 3 with headers.