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)
- {
- 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[x];
- int sum = 0;
- bool check;
- int maxValue,maxIndex;
- Random random = new Random();
- int rand;
- for (int i = 0; i < x; i++)
- {
- for (int j = 0; j < y; j++)
- {
- rand = random.Next(0, 100);
- if (rand % 2 == 0)
- {
- M[i, j] = rand - 1;
- }
- else
- {
- 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();
- }
- for (int i = 0; i < x; i++)
- {
- check = true;
- sum = 0;
- for (int j = 0; j < y; j++)
- {
- if (M[i, j] % 2 == 1)
- {
- sum += (Math.Abs(M[i, j]));
- }
- }
- if (check == false)
- {
- sum = 0;
- continue;
- }
- R[i] = sum;
- }
- Console.WriteLine("\n");
- maxValue = R.Max();
- maxIndex = (R.ToList().IndexOf(maxValue)+1);
- Console.WriteLine("Cтрока с максимальной суммой модулей элементов. " + maxIndex);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement