I am trying to make an app that adds the lines and columns of a matrix. The logic behind the app is that you input in a textbox each line of the matrix on a single line and separate every line with "/". For example: 1 2 3 4/1 2 3 4. Im trying to convert the values from string to int but I keep getting the argument 1 error.
Edit: forgot to add the function for the adding of the rows.
if (decision == 2)
{
string[] tokens = a.Split('/');
int[][] tokens1 = new int[][] {
tokens[0].Split(' ').Select(Int32.Parse).ToArray(),
tokens[1].Split(' ').Select(Int32.Parse).ToArray()
};
row_sum(tokens1, 2);
}
static void row_sum(int[,] arr, int orden)
{
int i, j, sum = 0;
// finding the row sum
for (i = 0; i < orden; ++i)
{
for (j = 0; j < orden; ++j)
{
// Add the element
sum = sum + arr[i, j];
}
// Print the row sum
Console.WriteLine("Sum of the row " +
i + " = " + sum);
// Reset the sum
sum = 0;
}
}