Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- namespace ExamPractice
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- int[,] array = new int[n, n];
- array = FillMatrix(n, array);
- PrintMatrix(n, array);
- int maxSum = MaxSum(n, array);
- Console.WriteLine("Сумата на всички положителни четни елементи е: " + maxSum);
- IndexOfMaxElement(n, array);
- }
- private static void IndexOfMaxElement(int n, int[,] array)
- {
- int maxNUmber = int.MinValue;
- int row = 0;
- int col = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- int currentNumber = array[i, j];
- if (currentNumber > maxNUmber)
- {
- maxNUmber = currentNumber;
- row = i;
- col = j;
- }
- }
- }
- Console.WriteLine($"Индексите на максималният елемент са: {row} и {col}");
- }
- private static int MaxSum(int n, int[,] array)
- {
- int sum = 0;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- if (array[i, j] > 0 && array[i, j] % 2 == 0)
- {
- sum += array[i, j];
- }
- }
- }
- return sum;
- }
- private static void PrintMatrix(int n, int[,] array)
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- Console.Write(array[i, j] + " ");
- }
- Console.WriteLine();
- }
- }
- private static int[,] FillMatrix(int n, int[,] array)
- {
- var lines = File.ReadLines("TxtFile");
- foreach (var line in lines)
- {
- int[] tokens = line.Split(' ').Select(int.Parse).ToArray();
- int element = tokens[0];
- int row = tokens[1];
- int col = tokens[1];
- array[row, col] = element;
- }
- return array;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement