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 Z_2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "Упорядочить каждую строку матрицы по возрастанию.";
- Console.Write("Ведите натуральное число, n= ");
- int n = int.Parse(Console.ReadLine());
- int[,] arr = new int[n, n];
- fillingArray(ref arr);
- display(arr);
- arrangeAscending(ref arr);
- display(arr);
- Console.ReadKey();
- }
- static void fillingArray(ref int[,] arr)
- {
- Random Rand = new Random();
- for (int i = 0; i < Math.Sqrt(arr.Length); i++)
- {
- for (int j = 0; j < Math.Sqrt(arr.Length); j++)
- {
- arr[i, j] = Rand.Next(9);
- }
- }
- }
- static void display(int[,] arr)
- {
- for (int i = 0; i < Math.Sqrt(arr.Length); i++)
- {
- for (int j = 0; j < Math.Sqrt(arr.Length); j++)
- {
- Console.Write("{0} ", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- static int counting(int[,] arr)
- {
- int count = 0;
- for (int i = 0; i < Math.Sqrt(arr.Length); i++)
- {
- for (int j = 0; j < i; j++)
- {
- if (arr[i, j] % 2 == 0)
- {
- count++;
- }
- }
- }
- return count;
- }
- static void arrangeAscending(ref int[,] arr)
- {
- for (int i = 0; i < Math.Sqrt(arr.Length); i++)
- {
- for (int k = 0; k < Math.Sqrt(arr.Length); k++)
- {
- for (int j = 0; j < (Math.Sqrt(arr.Length))-1; j++)
- {
- int temp;
- if (arr[i,j]>arr[i,j+1])
- {
- temp = arr[i,j];
- arr[i, j] = arr[i, j + 1];
- arr[i, j + 1] = temp;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement