Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace text
- {
- class MainClass
- {
- public static void Max(int[] a, int[] b)
- {
- int [] idmax = new int [3];
- for (int t = 0; t < 3; t++)
- {
- int j = a[0];
- int id = 0;
- int pr = 0;
- if (t > 0)
- {
- for (int i = 1; i < a.Length; i++)
- {
- for (int g = 0; g < t; g++)
- {
- if (i == idmax[g])
- {
- pr++;
- break;
- }
- }
- if (pr == 0)
- {
- if (a[i] > j)
- {
- j = a[i];
- id = i;
- }
- }
- }
- }
- else
- {
- for (int i = 1; i < a.Length; i++)
- {
- if (a[i] > j)
- {
- j = a[i];
- id = i;
- }
- }
- }
- b[t] = j;
- idmax[t] = id;
- }
- }
- public static void Main(string[] args)
- {
- Console.WriteLine("Количество столбцов");
- int n = int.Parse(Console.ReadLine());
- int [,] A = new int[n, n];
- int k = 0;
- for (int i = 0; i < n; i++)
- {
- for (int t = n - 1 - i; t < n; t++)
- {
- k++;
- }
- }
- Random rnd = new Random();
- for (int i = 0; i<n; i++)
- {
- for (int t = 0; t<n; t++)
- {
- A[t, i] = rnd.Next(1,100);
- }
- }
- Console.WriteLine("Матрица");
- for (int i = 0; i<n; i++)
- {
- for (int t = 0; t<n; t++)
- {
- Console.Write("{0} ", A[t, i]);
- }
- Console.WriteLine();
- }
- int[] p = new int[k];
- int l = 0;
- for (int i = 0; i<n; i++)
- {
- for (int t = n - 1 - i; t<n; t++)
- {
- p[l] = A[t, i];
- l++;
- }
- }
- int[] max = new int[3];
- Max(p, max);
- Console.WriteLine("Вектор");
- Console.Write("{ ");
- for (int i = 0; i < k; i++)
- {
- Console.Write("{0}, ", p[i]);
- }
- Console.WriteLine(" }");
- Console.WriteLine("Максмальные элементы");
- for (int i = 0; i < 3; i++)
- {
- Console.Write("{0} ", max[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement