Найти сумму столбцов матрицы - C#
Формулировка задачи:
Здравствуйте, помогите, пожалуйста, понять почему не считает сумму столбцов:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication18
{
class Program
{
static void Main(string[] args)
{
int n,m;
n=2;
m=3;
int sum = 0;
int [,] mas=new int[n,m];
Console.WriteLine("Заполните матрицу");
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
{
mas[i, j] = Int32.Parse(Console.ReadLine());
}
}
Console.WriteLine("Полученная матрица:");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
Console.Write(mas[i, j]+" ");
}
Console.WriteLine("\n");
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
sum+=mas[i, j];
}
Console.Write(sum + " ");
}
Console.ReadLine();
}
}
}Решение задачи: «Найти сумму столбцов матрицы»
textual
Листинг программы
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
sum+=mas[j, i];
}
Console.Write(sum + " ");
sum=0;
}