Created
May 12, 2016 17:52
-
-
Save bolenton/576683cb68b81333b165a3769176a34d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace MatrixAssignment | |
{ | |
class Matrix | |
{ | |
public static int[,] CreateGrid(int rows, int cols) | |
{ | |
int[,] grid = new int[rows, cols]; | |
int cells = grid.GetLength(0) * grid.GetLength(1); | |
for (int row = 0; row < rows; row++) | |
{ | |
for (int col = 0; col < cols; col++) | |
{ | |
Console.WriteLine("Enter you number for cell {0}", cells); | |
grid[row, col] = int.Parse(Console.ReadLine()); | |
cells--; | |
} | |
} | |
return grid; | |
} | |
public static void PopulateGrid(int[,] grid) | |
{ | |
Console.WriteLine("\n Here is the Grid"); | |
for (int row = 0; row < grid.GetLength(0); row++ ) | |
{ | |
for (int col = 0; col < grid.GetLength(1); col++) | |
{ | |
Console.Write(grid[row, col] + " "); | |
} | |
Console.WriteLine(); | |
} | |
} | |
public static void CalculateMatrix(int [,] grid1, int [,] grid2, int rows, int cols) | |
{ | |
int[,] grid3 = new int[rows, cols]; | |
for (int row = 0; row < rows; row++) | |
{ | |
for (int col = 0; col < cols; col++) | |
{ | |
grid3[row, col] = grid1[row, col] + grid2[row, col]; | |
} | |
} | |
for (int row = 0; row < grid3.GetLength(0); row++) | |
{ | |
for (int col = 0; col < grid3.GetLength(1); col++) | |
{ | |
Console.Write(grid3[row, col] + " "); | |
} | |
Console.WriteLine(); | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using System.Threading.Tasks; | |
namespace MatrixAssignment | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("How many rows would you like?"); | |
int row = int.Parse(Console.ReadLine()); | |
Console.WriteLine("How many columns would you like?"); | |
int col = int.Parse(Console.ReadLine()); | |
int [,] grid1 = Matrix.CreateGrid(row, col); | |
Matrix.PopulateGrid(grid1); | |
Console.WriteLine("\n Now for the second Grid"); | |
int[,] grid2 = Matrix.CreateGrid(row, col); | |
Matrix.PopulateGrid(grid2); | |
Console.WriteLine("I am now going to add the 2 Grids together, Press return to continue...."); | |
Console.ReadLine(); | |
Matrix.CalculateMatrix(grid1, grid2, row, col); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment