Advertisement
ElliasBLR

Max4

Oct 7th, 2020
1,750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.        
  11.         static void Main(string[] args)
  12.         {
  13.             /*19.   Найти наибольшую сумму модулей элементов строк заданной матрицы.
  14.              */
  15.             Console.Write("Введите размеры матрицы: \n");
  16.             int x = Convert.ToInt16(Console.ReadLine());
  17.             int y = Convert.ToInt16(Console.ReadLine());
  18.             int[,] M = new int[x, y];
  19.             int[] R = new int[y];
  20.             int sum = 0;
  21.             int max = 0;
  22.            
  23.             Random random = new Random();
  24.             int rand;
  25.             for (int i = 0; i < x; i++)
  26.             {
  27.                 for (int j = 0; j < y; j++)
  28.                 {
  29.                     rand = random.Next(-100, 100);
  30.                     M[i, j] = rand;
  31.                 }
  32.             }
  33.  
  34.             Console.WriteLine("Исходная матрица: ");
  35.             for (int i = 0; i < x; i++)
  36.             {
  37.                 for (int j = 0; j < y; j++)
  38.                 {
  39.                     Console.Write(M[i, j] + "\t");
  40.                 }
  41.                 Console.WriteLine();
  42.             }
  43.  
  44.             //creating another array
  45.             for (int i = 0; i < x; i++)
  46.             {
  47.                 sum = Math.Abs(M[i, 0]);
  48.                 for(int j = 1;j < y;j++)
  49.                 {
  50.                     sum += Math.Abs(M[i, j]);
  51.                 }
  52.                 R[i] = sum;
  53.             }
  54.             //result
  55.             max = R[0];
  56.             for (int i = 1; i < R.Length; i++)
  57.             {
  58.                 if (max < R[i])
  59.                 {
  60.                     max = R[i];
  61.                 }
  62.             }
  63.             Console.WriteLine("Наибольшая сумма модулей элементов строки = " + max);
  64.  
  65.             Console.ReadKey();
  66.  
  67.         }
  68.     }
  69. }
  70.  
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement