Черников / Домашние задания / ДЗ-5 / Задание / 34 / Вариант_25
.docЗадача 1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int m = 0, n = 0;
double[][] mas;
List<double> d;
char rep;
do
{
try
{
Console.WriteLine("Вас приветствует программа вычленяющая из двумерного массива все отрицательные элементы");
Console.WriteLine("Введите колличество столбцов матрицы:");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Введите колличество сторок матрицы:");
n = int.Parse(Console.ReadLine());
}catch { Console.WriteLine("Некоректно введены даныне"); }
mas = new double[m][];
for (int i = 0; i < mas.Length; i++)
mas[i] = new double[m];
d = new List<double>();
d.Add(1);
Metod.Zapolnenie(mas);
Metod.Show(mas);
Metod.CopyOtric(mas, out d);
for (int i = 0; i < d.Count; i++)
Console.Write("Oтриц знач:{0,4:f2}", d);
Console.WriteLine("Поторить? Y/N");
rep = char.Parse(Console.ReadLine());
}while(rep=='Y'||rep=='y');
}
}
}
Задача 2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Фролова_Светлана_175
{
class Program
{
static int[][] generator(int n)
{ char rep;
REPEAT:
int[][] a = new int[n][];
Random r = new Random();
for (int i = 0; i < n; i++)
a[i] = new int[r.Next(1, 10)];
return a;
}
static bool simple(int n)
{ if (n < 4)
return true;
for (int i = 2; i < n - 1; i++)
if (n / i * i == n)
return false;
return true; }
static void Main(string[] args)
{
Console.Write("Input n: ");
int n = int.Parse(Console.ReadLine());
Random r = new Random();
int[][] a = generator(n);
int[] s = new int[n];
for (int i = 0; i < n; i++)
for (int j = 0; j < a[i].Length; j++)
a[i][j] = r.Next(100);
Console.WriteLine();
Console.WriteLine("Array a:");
for (int i = 0; i < n; i++)
{ for (int j = 0; j < a[i].Length; j++)
Console.Write(a[i][j].ToString() + ' ');
Console.WriteLine(); }
for (int i = 0; i < n; i++)
s[i] = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < a[i].Length; j++)
if(simple(a[i][j]))
s[i]++;
Console.WriteLine();
Console.WriteLine("Array s:");
for (int i = 0; i < n; i++)
Console.Write(s[i].ToString() + ' ');
Console.ReadLine();
Console.WriteLine("Программа выполнена. Повторить?");
rep = char.Parse(Console.ReadLine());
if (rep == 'Y' || rep == 'y') goto REPEAT;
Console.ReadLine();
}
}
}
Задача 3.
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class MyClass
{
public static void Random(int[,] mas, int N, int M)
{
Random g = new Random();
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
mas[i, j] = g.Next(15, 51);
}
}
Vivod(mas, N, M);
}
public static void Vivod(int[,] mass, int n1, int m1)
{
for (int i = 0; i < n1; i++)
{
Console.WriteLine();
for (int j = 0; j < m1; j++)
{
Console.Write("{0,4}", mass[i, j]);
}
}
}
public static void Sdvig(int[]s,int M )
{
for(int i=1; i<M; i++)
{
s[i-1]=s[i];
if(i==M-1) s[i]=0;
} Vivod2(s, M);
}
public static void Vivod2(int[] mass, int n1)
{
for (int i = 0; i < n1; i++)
{
Console.Write("{0,4}", mass[i]);
}
}
}
class Program
{
static void Main(string[] args)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.BackgroundColor = ConsoleColor.DarkBlue;
char rep;
do
{
Console.Clear();
Console.WriteLine("Добрый день! Спасибо, что используете нашу программу!");
int N, M;
Console.WriteLine("Введите количество строк матрицы: ");
N = int.Parse(Console.ReadLine());
Console.WriteLine("Введите количество столбцов в матрице: ");
M = int.Parse(Console.ReadLine());
int[,] a = new int[N, M];
Console.WriteLine("Исходная матрица: ");
Console.Write('\n');
MyClass.Random(a, N, M);
Console.Write('\n');
int[] s = new int[M];
Console.WriteLine();
Console.WriteLine("Полученная матрица: ");
Console.Write('\n');
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
s[j] = a[i, j];
}
MyClass.Sdvig(s, M);
Console.Write(" \n", s);
}
Console.WriteLine("Для повтора программы введите Y: ");
rep = char.Parse(Console.ReadLine());
Console.Write('\n');
}
while (rep == 'y' || rep == 'Y');
Console.ReadLine();
}
}
}