Найти сумму и произведение элементов K-го столбца матрицы - C# (187894)
Формулировка задачи:
Matrix18. Дана матрица размера M x N и целое число K (1 <= K <= N). Найти сумму и произведение элементов K-го столбца данной матрицы.
Решение задачи: «Найти сумму и произведение элементов K-го столбца матрицы»
textual
Листинг программы
static void Show(int[,] mas)
{
for (int i = 0; i < mas.GetLength(0); i++)
{
for (int j = 0; j < mas.GetLength(1); j++)
{
Console.Write(mas[i, j] + " ");
}
Console.WriteLine();
}
}
static void Main(string[] args)
{
Random r = new Random();
Console.Write("Введите размерность M: ");
int M = Convert.ToInt16(Console.ReadLine());
Console.Write("Введите размерность N: ");
int N = Convert.ToInt16(Console.ReadLine());
Console.Write("Введите размерность K: ");
int K = Convert.ToInt16(Console.ReadLine());
int[,] array = new int[M, N];
for (int i = 0; i < array.GetLength(0); i++)
{
for (int j = 0; j < array.GetLength(1); j++)
{
array[i, j] = r.Next(0, 10);
}
}
Show(array);
int sum = 0;
int mul = 1;
for (int i = 0; i < array.GetLength(0); i++)
{
sum += array[i, K];
mul *= array[i, K];
}
Console.WriteLine(string.Format("Sum: {0}, Mul: {1}", sum, mul));
Console.ReadLine();
}