Задача 1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Суворов_Игорь
{
class Program
{
static void Main(string[] args)
{
ConsoleKeyInfo e;
ConsoleKeyInfo
Console.BackgroundColor = ConsoleColor.DarkBlue;
Console.Title = "Контрольная работа №2";
do
{
Console.Clear();
int n,
repeatInput:
try
{
Console.Write("Введите количество строк:");
n = int.Parse(Console.ReadLine());
Console.Write("Введите количество столбцов:");
m = int.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Нужно ввести целое положительное число");
goto repeatInput;
}
Console.WriteLine();
MyClass ob = new MyClass() ;
int[,] a = new int[n, m];
ob.randMass(a);
Console.WriteLine("Исходный массив:");
ob.print(a);
Console.WriteLine();
int[,] b = new int[n, m];
b = ob.sort(ref a);
Console.WriteLine("Отсортированный массив:");
ob.print(b);
Console.WriteLine();
Console.WriteLine("Для выхода нажмите клавишу Esc");
e = Console.ReadKey();
} while (e.Key != ConsoleKey.Escape);
}
}
}
Задача 2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace Сулейманов
{
class Program
{
static void Main(string[] args)
{
Console.BackgroundColor = ConsoleColor.Gray;
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Write("Введите n: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write("Введите m: ");
int m = Convert.ToInt32(Console.ReadLine());
int[,] a = new int[n, m];
Arrays k = new Arrays();
k.Fill(a);
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("\nМассив:");
k.Write(a);
ArrayList array;
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("\nЧетные: ");
k.CopyNum(a, n, m, out array);
for (int i = 0; i < array.Count; i++) Console.Write(array[i] + " ");
Console.ReadLine();
}
}
}
Задача 3.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication2
{
class Metods
{
public static int[] Заполнениемассива(int n, out int[] b)
{
int i;
int[] a= new int[n];
Random gen=new Random();
b = new int[n];
for (i = 0; i < n; i++)
{
a[i] = gen.Next(-100,301);
b[i] = a[i];
}
return a;
}
public static void Выводмассива(int n, int[] a) /
{
int i, j;
Console.WriteLine("Массив получился следующий :");
for (i = 0; i < n; i++)
{
Console.Write("{0} ", a[i]);
}
}
public static void Динамический(int[] a, int n, out ArrayList al)
{
int i;
al = new ArrayList();
for (i = 0; i < n; i++)
if (a[i]>0)
al.Add(a[i]);
}
public static void Выводдинамическогомассива(ArrayList al)
{
int i;
for (i = 0; i < al.Count; i++)
Console.Write("{0} ", al[i]);
Console.WriteLine();
}
}
class Program
{
static void Main(string[] args)
{
string str;
int n;
int i;
int [] b;
bool er;
char rep;
ArrayList al;
ArrayList c;
c = new ArrayList();
Console.BackgroundColor = ConsoleColor.Yellow;
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.Clear();
do
{
try
{
do
{
Console.Clear();
DateTime dt = DateTime.Now;
Console.WriteLine("{0:F}", dt);
Console.WriteLine("Сколько чисел будет в нашем первом массиве?");
str = Console.ReadLine();
n = int.Parse(str);
Metods.Заполнениемассива(n, out b);
Metods.Выводмассива(n,b);
Console.WriteLine();
Metods.Динамический(b, n, out al);
Console.WriteLine();
Console.WriteLine("список элементов, которые скопируются в итоговый массив из данного");
if (al.Count == 0)
Console.WriteLine("Нет никаких положительных значений");
else
Metods.Выводдинамическогомассива(al);
Console.WriteLine("================================================================================");
for (i = 0; i < al.Count; i++)
c.Add(al[i]);
Console.WriteLine("Сколько чисел будет в нашем втором массиве?");
str = Console.ReadLine();
n = int.Parse(str);
Metods.Заполнениемассива(n, out b);
Metods.Выводмассива(n, b);
Console.WriteLine();
Metods.Динамический(b, n, out al);
Console.WriteLine();
Console.WriteLine("список элементов, которые скопируются в итоговый массив из данного");
if (al.Count == 0)
Console.WriteLine("Нет никаких положительных значений");
else
Metods.Выводдинамическогомассива(al);
Console.WriteLine("================================================================================");
for (i = 0; i < al.Count; i++)
c.Add(al[i]);
Console.WriteLine("Итоговый массив со всеми положительными элементами из двух вышеуказанных");
if (c.Count == 0)
Console.WriteLine("Нет никаких положительных значений");
else
Metods.Выводдинамическогомассива(c);
Console.WriteLine();
Console.WriteLine("Если хотите протестировать ещё раз то нажмите Y");
rep = char.Parse(Console.ReadLine());
}
while (rep == 'y' || rep == 'Y');
er = false;
}
catch (FormatException e)
{
Console.Clear();
Console.WriteLine(e.Message);
er = true;
}
}
while (er == true);
}
}
}