Advertisement
ElliasBLR

lab4 OAIP

Sep 27th, 2020
949
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 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.         static void Main(string[] args)
  11.         {
  12.             Console.Write("Введите размеры матрицы: \n");
  13.             int x = Convert.ToInt16(Console.ReadLine());
  14.             int y = Convert.ToInt16(Console.ReadLine());
  15.             int[,] M = new int[x,y];
  16.             int[] R = new int[x];
  17.             int sum = 0;
  18.             bool check;
  19.             int maxValue,maxIndex;
  20.             Random random = new Random();
  21.             int rand;
  22.             for (int i = 0; i < x; i++)
  23.             {
  24.                 for (int j = 0; j < y; j++)
  25.                 {
  26.                     rand = random.Next(0, 100);
  27.                     if (rand % 2 == 0)
  28.                     {
  29.                         M[i, j] = rand - 1;
  30.                     }
  31.                     else
  32.                     {
  33.                         M[i, j] = rand;
  34.                     }
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine("Исходная матрица: ");
  39.             for (int i = 0; i < x; i++)
  40.             {
  41.                 for (int j = 0; j < y; j++)
  42.                 {
  43.                     Console.Write(M[i, j] + "\t");
  44.                 }
  45.                 Console.WriteLine();
  46.             }
  47.  
  48.            
  49.             for (int i = 0; i < x; i++)
  50.             {
  51.                 check = true;
  52.                 sum = 0;
  53.                 for (int j = 0; j < y; j++)
  54.                 {
  55.                     if (M[i, j] % 2 == 1)
  56.                     {
  57.                         sum += (Math.Abs(M[i, j]));
  58.                     }
  59.        
  60.                 }
  61.                 if (check == false)
  62.                 {
  63.                     sum = 0;
  64.                     continue;
  65.                 }
  66.                 R[i] = sum;
  67.             }
  68.             Console.WriteLine("\n");
  69.             maxValue = R.Max();
  70.             maxIndex = (R.ToList().IndexOf(maxValue)+1);
  71.             Console.WriteLine("Cтрока с максимальной суммой модулей элементов. " + maxIndex);
  72.  
  73.             Console.ReadKey();
  74.  
  75.         }
  76.        
  77.         }
  78.     }
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement