Advertisement
filin

laba_4_z_2_mk1

Sep 25th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 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.  
  7. namespace Z_2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Упорядочить каждую строку матрицы по возрастанию.";
  14.             Console.Write("Ведите натуральное число, n= ");
  15.             int n = int.Parse(Console.ReadLine());
  16.             int[,] arr = new int[n, n];
  17.             fillingArray(ref arr);
  18.             display(arr);
  19.             arrangeAscending(ref arr);
  20.             display(arr);
  21.             Console.ReadKey();
  22.         }
  23.         static void fillingArray(ref int[,] arr)
  24.         {
  25.             Random Rand = new Random();
  26.             for (int i = 0; i < Math.Sqrt(arr.Length); i++)
  27.             {
  28.                 for (int j = 0; j < Math.Sqrt(arr.Length); j++)
  29.                 {
  30.                     arr[i, j] = Rand.Next(9);
  31.                 }
  32.             }
  33.         }
  34.         static void display(int[,] arr)
  35.         {
  36.             for (int i = 0; i < Math.Sqrt(arr.Length); i++)
  37.             {
  38.                 for (int j = 0; j < Math.Sqrt(arr.Length); j++)
  39.                 {
  40.                     Console.Write("{0} ", arr[i, j]);
  41.                 }
  42.                 Console.WriteLine();
  43.             }
  44.         }
  45.         static int counting(int[,] arr)
  46.         {
  47.             int count = 0;
  48.             for (int i = 0; i < Math.Sqrt(arr.Length); i++)
  49.             {
  50.                 for (int j = 0; j < i; j++)
  51.                 {
  52.                     if (arr[i, j] % 2 == 0)
  53.                     {
  54.                         count++;
  55.                     }
  56.                 }
  57.             }
  58.             return count;
  59.         }
  60.         static void arrangeAscending(ref int[,] arr)
  61.         {
  62.             for (int i = 0; i < Math.Sqrt(arr.Length); i++)
  63.             {
  64.                 for (int k = 0; k < Math.Sqrt(arr.Length); k++)
  65.                 {
  66.                     for (int j = 0; j < (Math.Sqrt(arr.Length))-1; j++)
  67.                     {
  68.                         int temp;
  69.                         if (arr[i,j]>arr[i,j+1])
  70.                         {
  71.                             temp = arr[i,j];
  72.                             arr[i, j] = arr[i, j + 1];
  73.                             arr[i, j + 1] = temp;
  74.                            
  75.                         }
  76.                     }
  77.                 }
  78.             }
  79.         }
  80.  
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement