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;
- using System.Threading.Tasks;
- namespace ConsoleApp6
- {
- class Program
- {
- static void Main(string[] args)
- {
- string str;
- int n;
- Console.WriteLine("Введите число строк и столбцов");
- str = Console.ReadLine();
- while (!int.TryParse(str, out n))
- {
- Console.WriteLine("Неправильный формат ввода");
- Console.WriteLine("Введите число элементов ");
- str = Console.ReadLine();
- }
- /*int m;
- Console.WriteLine("Введите число столбцов");
- str = Console.ReadLine();
- while (!int.TryParse(str, out m)&&m!=n)
- {
- Console.WriteLine("Неправильный формат ввода");
- Console.WriteLine("Введите ЧИСЛО элементов ");
- str = Console.ReadLine();
- }*/
- int[,] a = new int[n, n];
- Matr.InSertMatr(n, a);
- Matr.OutPutMatr(n, a);
- Console.WriteLine();
- //if (Matr.Seach(a,n)>0)
- Console.WriteLine("Сумма элементов столбцов,не содержащих отрицательных элементов:", Matr.Sum(a, n));
- Console.WriteLine();
- Console.WriteLine("Минимум среди сумм модулей элементов диагоналей, параллельных побочной диагонали матрицы:", Matr.Min(a, n));
- Console.ReadKey();
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp6
- {
- class Matr
- {
- public static void InSertMatr(int n, int[,] a)
- {
- Random rand = new Random();
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- a[i, j] = rand.Next(-50, 50);
- }
- }
- }
- public static void OutPutMatr(int n, int[,] a)
- {
- Console.WriteLine("Сгенерированная матрица: ");
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- Console.Write("{0, 5}", a[i, j]);
- Console.WriteLine();
- }
- }
- public static int Sum(int[,] a, int n)
- {
- int summ = 0;
- for (int j = 0; j < n; j++)
- {
- int sumj = 0;
- for (int i = 0; i < n; i++)
- {
- while (a[i, j] >= 0 && i < n)
- {
- sumj += a[i, j];
- if (sumj < 0)
- { sumj = 0; }
- }
- }
- summ += sumj;
- }
- return summ;
- }
- public static int Min(int [,] a, int n)
- {
- int minSum = 32000, b, c;
- for (int i = 1; i < n - 1; i++)
- {
- b = 0;
- c = 1000;
- for (int j = 0; j < n - i; j++)
- {
- b += Math.Abs(a[j + i, j]);
- c += Math.Abs(a[j, j + i]);
- }
- if (b< minSum || c < minSum) minSum = (b < c) ? b : c;
- }
- return minSum;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement