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)
- {
- for (int i = 0; i < array.Length; i++)
- {
- bool flag = false;
- for (int j = 0; j < array[i].Length; j++)
- if (array[i][j] % 2 != 0)
- {
- flag = true;
- break;
- }
- if (flag)
- {
- Random rdm = new Random();
- Array.Resize(ref array, array.Length + 1);
- array[array.Length-1] = new int [array[i].Length];
- for (int p = array.Length-1; p > i; p--)
- array[p-1].CopyTo(array[p], 0);
- /*for (int k = 0; k < array[i].Length; k++)
- array[p][k] = array[p-1][k];*/
- for (int j = 0; j < array[i].Length; j++)
- array[i][j] = rdm.Next(10);
- }
- }
- }
- static void Print(int[][] array)
- {
- 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