Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.34 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace matrica
  7. {
  8.     class Program
  9.     {
  10.         public static int[,] vector = new int[5,5];
  11.         public static int counterLine = 0, Maxcounter = 0, Mincounter = 0, srednie;
  12.         public static int[] min_index = new int[2], max_index = new int[2];
  13.         static void Main(string[] args)
  14.         {
  15.             Random r = new Random();
  16.             Console.WriteLine("Matrix: ");
  17.             for (int i = 0; i < 5; i++)
  18.             {
  19.                 for (int k = 0; k < 5; k++)
  20.                 {
  21.                     vector[i, k] = r.Next(25);
  22.                     counterLine++;
  23.                     Console.Write(vector[i, k] + " ");
  24.                     if (counterLine == 5)
  25.                     {
  26.                         Console.Write(System.Environment.NewLine);
  27.                         counterLine = 0;
  28.                     }
  29.                 }
  30.             }
  31.             Console.Write(System.Environment.NewLine);
  32.             Mincounter = 300;
  33.             for (int i = 0; i < 5; i++)
  34.                 for (int y = 0; y < 5; y++)
  35.                     Console.WriteLine("Index(" + i + ";" + y + ") = " + vector[i, y]);
  36.             Console.Write(System.Environment.NewLine);
  37.             for (int h = 0; h < 5; h++)
  38.                 for(int y = 0; y < 5; y++)
  39.                 {
  40.                     if (vector[h, y] > Maxcounter) { Maxcounter = vector[h, y]; max_index[0] = h; max_index[1] = y; }
  41.                     if (vector[h, y] < Mincounter) { Mincounter = vector[h, y]; min_index[0] = h; min_index[1] = y; }
  42.                 }
  43.             Console.WriteLine("Max index(" + max_index[0].ToString() + ";" + max_index[1].ToString() + ")");
  44.             Console.WriteLine("Min index(" + min_index[0].ToString() + ";" + min_index[1].ToString() + ")");
  45.             Console.Write(System.Environment.NewLine);
  46.             for (int i = 0; i < 5; i++)
  47.                 for(int j = 0; j < 5; j++)
  48.                     srednie += vector[i, j];
  49.             float result = srednie / 2;
  50.             Console.WriteLine("Сума значений матрицы: " + srednie.ToString());
  51.             Console.WriteLine("Средние значение матрицы: " + result.ToString());
  52.             Console.ReadLine();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement