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;
- namespace practice
- {
- class Program
- {
- static void Input(out int[][] array)
- {
- Console.Write("Введите размерность матрицы n: ");
- int n = int.Parse(Console.ReadLine());
- array = new int[n][];
- Random rdm = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = new int[n];
- for (int j = 0; j < array[i].Length; j++)
- {
- array[i][j] = rdm.Next(10);
- }
- }
- Console.WriteLine("Исходный массив: ");
- for (int i = 0; i < array.Length; i++)
- {
- for (int j = 0; j < array[i].Length; j++)
- Console.Write("{0} ", array[i][j]);
- Console.WriteLine();
- }
- }
- static void Change(ref int[][] array)
- {
- Random rdm = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- bool flag = true;
- for (int j = 0; j < array[i].Length; j++)
- if (array[i][j] % 2 == 0)
- {
- flag = false;
- break;
- }
- if (flag)
- {
- Insert(ref array, i);
- for (int j = 0; j < array[i + 1].Length; j++)
- array[i + 1][j] = rdm.Next(10);
- i++;
- }
- }
- }
- static void Insert(ref int[][] array, int index)
- {
- Array.Resize(ref array, array.Length + 1);
- array[array.Length - 1] = new int[array[0].Length];
- for (int i = array.Length - 1; i > index; i--)
- //array[i - 1].CopyTo(array[i], 0);
- for (int j = 0; j < array[0].Length; j++)
- array[i][j] = array[i-1][j];
- }
- static void Print(int[][] array)
- {
- Console.WriteLine("Изменённый массив: ");
- for (int i = 0; i < array.Length; i++)
- {
- for (int j = 0; j < array[i].Length; j++)
- Console.Write("{0} ", array[i][j]);
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- int[][] array;
- Input(out array);
- Change(ref array);
- Print(array);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement