Задача 1.
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace Program
{
class Program
{
static void Main(string[] args)
{
char s;
rep: Console.BackgroundColor = ConsoleColor.Cyan;
Console.ForegroundColor = ConsoleColor.DarkRed;
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("Данный массив:");
k.Write(a);
ArrayList array;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Четные элементы массива: ");
k.CopyNum(a, n, m, out array);
for (int i = 0; i < array.Count; i++) Console.Write(array[i] + " ");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Magenta;
Console.WriteLine("Желаете повторить программу?Y/N");
s = char.Parse(Console.ReadLine());
if (s == 'y' || s == 'Y') goto rep;
}
}
}
Задача 2.
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace Program
{
class Arrays
{
public void Write(int[,] a)
{
for (int i = 0; i < a.GetLength(0); i++, Console.WriteLine())
for (int j = 0; j < a.GetLength(1); j++)
Console.Write("{0,1} ", a[i, j]);
}
public void CopyNum(int[,] a, int n, int m, out ArrayList array)
{
array = new ArrayList();
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (a[i, j] % 2 == 0) array.Add(a[i, j]);
}
}
}
public void Fill(int[,] a)
{
var r = new Random(Convert.ToInt32(DateTime.Now.Ticks % 10));
for (var i = 0; i < a.GetLength(0); i++)
for (var j = 0; j < a.GetLength(1); j++) a[i, j] = r.Next(1,10);
}
public void Write(int[] a)
{
foreach (var i in a)
{
Console.Write("{0,1} ", i);
}
}
}
}
Задача 3.
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Metod
{
public void Zap(double[,] mas, int m, int n, double max, double min)
{
int i, j;
Random gen = new Random();
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
mas[i, j] = max - (max - min) * gen.NextDouble();
}
}
public void Vivod(double[,] mas, int m, int n)
{
int i, j;
Console.WriteLine();
Console.WriteLine("Массив:");
for (i = 0; i < m; i++)
{
Console.WriteLine();
for (j = 0; j < n; j++)
Console.Write( " "+mas[i, j] + " ");
}
}
public bool Znak(double ch, out bool otvet)
{ otvet=true;
if (ch>0) otvet=true;
else otvet=false;
return otvet;
}
}
class Program
{
static void Main(string[] args)
{ int i,j,M, N,k;
double min, max;
bool z=false;
Console.WriteLine("Введите количество строк в массиве:");
M = int.Parse(Console.ReadLine());
Console.WriteLine("Введите количество столбцов в массиве:");
N = int.Parse(Console.ReadLine());
Console.WriteLine("Введите минимальные рамки элементов массива:");
min = double.Parse(Console.ReadLine());
Console.WriteLine("Введите максимальные рамки элементов массива:");
max = double.Parse(Console.ReadLine());
double[,] mas = new double[M, N];
Metod ob = new Metod();
ob.Zap(mas, M, N, max, min);
ob.Vivod(mas, M, N);
Console.WriteLine();
for (i=0;i<M;i++)
{k = 0;
for (j=0;j<N;j++)
ob.Znak(mas[i,j],out z);
if (z==true) k++;
Console.WriteLine("Количество положительных чисел в " + (i+1) + " строке=" + k);
} Console.ReadLine();
}
}
}