Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*19. Найти наибольшую сумму модулей элементов строк заданной матрицы.
- */
- Console.Write("Введите размеры матрицы: \n");
- int x = Convert.ToInt16(Console.ReadLine());
- int y = Convert.ToInt16(Console.ReadLine());
- int[,] M = new int[x, y];
- int[] R = new int[y];
- int sum = 0;
- int max = 0;
- Random random = new Random();
- int rand;
- for (int i = 0; i < x; i++)
- {
- for (int j = 0; j < y; j++)
- {
- rand = random.Next(-100, 100);
- M[i, j] = rand;
- }
- }
- Console.WriteLine("Исходная матрица: ");
- for (int i = 0; i < x; i++)
- {
- for (int j = 0; j < y; j++)
- {
- Console.Write(M[i, j] + "\t");
- }
- Console.WriteLine();
- }
- //creating another array
- for (int i = 0; i < x; i++)
- {
- sum = Math.Abs(M[i, 0]);
- for(int j = 1;j < y;j++)
- {
- sum += Math.Abs(M[i, j]);
- }
- R[i] = sum;
- }
- //result
- max = R[0];
- for (int i = 1; i < R.Length; i++)
- {
- if (max < R[i])
- {
- max = R[i];
- }
- }
- Console.WriteLine("Наибольшая сумма модулей элементов строки = " + max);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement