Черников / Домашние задания / ДЗ-5 / Задание / 34 / Вариант_13
.docЗадача 1.
using System;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public int m, n;
public int i, j;
static void Main(string[] args)
{
char re;
Program one = new Program();
Class1 two = new Class1();
do
{
Console.WriteLine("Введите количество строк массива: ");
one.m = int.Parse(Console.ReadLine());
Console.WriteLine("Введите количество столбцов массива: ");
one.n = int.Parse(Console.ReadLine());
Random ran = new Random();
double[,] array1 = new double[one.m, one.n]
for (one.i = 0; one.i < one.m; one.i++)
{
for (one.j = 0; one.j < one.n; one.j++)
{
array1[one.i, one.j] = (ran.Next(-124, 217) / 10);
}
}
for (one.i = 0; one.i < one.m; one.i++)
{
for (one.j = 0; one.j < one.n; one.j++)
{
Console.Write(array1[one.i, one.j] + " ");
}
Console.WriteLine();
}
double[] array2 = new double[one.m];
double s;
int a;
a = 0;
for (one.i = 0; one.i < one.m; one.i++)
{
for (one.j = 0; one.j < one.n; one.j++)
{
array1[one.i, one.j] = s;
if (s < 0)
{
a = a + 1;
array2[a] = s;
}
}
}
Console.WriteLine("Повторить выполение программы? [y/n]");
re = char.Parse(Console.ReadLine());
} while (re == 'y');
}
}
}
Задача 2.
using System;
namespace program1
{
class Program
{
static void Main(string[] args)
{
Class1 ob = new Class1();
Console.Title = "Никольская,175 группа, вариант 12";
Console.ForegroundColor = ConsoleColor.Black;
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
char f;
do
{
int[,] a;
int n= 0, m = 0, l = 0;
do
{
Console.WriteLine("введите кол-во строк :");
try
{
n = int.Parse(Console.ReadLine());
l = 1;
}
catch
{
Console.WriteLine("неверные данные,введите снова");
}
}
while (l != 1);
l = 0;
do
{
Console.WriteLine("введите кол-во столбцов :");
try
{
m = int.Parse(Console.ReadLine());
l = 1;
}
catch
{
Console.WriteLine("неверные данные, введите снова");
}
}
while (l != 1);
a = new int[n, m];
ob.create(a, n, m);
ob.print(a, n,m);
ob.pruznak(a, n, m);
Console.Write("Для выхода из программы нажмите y ");
Console.Write("\n");
Console.Write("Для повторения программы нажмите n ");
Console.Write("\n");
f = char.Parse(Console.ReadLine());
}
while (f == 'n' || f == 'N');
}
}
}
Задача 3.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class MyMetod
{
public static void sdvig(int[] a, int m)
{
int i;
a = new int[m];
a[m - 1] = 0;
for (i = 0; i <m-2; i++)
a[i] = a[i + 1];
}
}
class Program
{
static void Main(string[] args)
{
int i,j;
int [][]a;
Random generator=new Random();
int n,m;
do
{
Console.WriteLine("Введите количество строк");
}while(!int.TryParse(Console.ReadLine(),out n)|n<0);
do
{
Console.WriteLine("Введите количество столбцов");
}while(!int.TryParse(Console.ReadLine(), out m)|m<0);
a=new int [n][];
for (i = 0; i < n; i++)
a[i] = new int[m];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
a[i][j] = generator.Next(15, 51);
Console.WriteLine("Изначальная матрица");
for (i = 0; i < n; i++, Console.WriteLine())
for (j = 0; j < m; j++)
Console.Write("{0,4}", a[i][j]);
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
MyMetod.sdvig(a[i], m);
Console.WriteLine("Переформированная матрица");
for (i = 0; i < n; i++, Console.WriteLine())
for (j = 0; j < m; j++)
Console.Write("{0,4}", a[i][j]);
}
}
}