I know this has been asked numerous times before, but I could not find what specifically I 'm looking for.
I'm currently trying to write c# method that displays int array as vertical bars on console. My idea is to transform 1D array into 2D.
if input = {2, 1, 3}; Output should look like:
{{0, 0, 1},
{1, 0, 1},
{1, 1, 1}}
Then I could replace 1 and 0 by character of my choice to display the image on the console. So far my method looks like this:
public static void DrawGraph()
{
int[] randomArray = new int[3]{ 2, 1, 3 };
int[,] graphMap = new int[3, 3];
for(int i = 0; i < graphMap.GetLength(0); i++)
{
for(int j = 0; j < graphMap.GetLength(1); j++)
{
graphMap[i, j] = randomArray[j];
Console.Write(graphMap[i, j]);
}
Console.WriteLine();
}
}
And it produces output:
2 1 3
2 1 3
2 1 3
{2, 1, 3}input result in{{0, 0, 1}, {1, 0, 1}, {1, 1, 1}}as output? Are you looking to make the columns of the 2D array sum up to the 1D array?graphMap[i, j]=randomArray[j];tographMap[i, j]=11:s are found vertically bottom-up in the resulting array. Think of it as a bar graph with 1:s as the bars.