Черников / Домашние задания / ДЗ-5 / Задание / 34 / Вариант_22
.docЗадача 1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double x, y=0;
string str;
char rep=' ';
do
{ Console.Clear();
Console.Write("введите значение x: ");
str=Console.ReadLine();
x=double.Parse(str);
if (x<=-2|| x>=2)
y=0;
if(x<=1 && x>=-1) y=-1;
if (x>1 && x<2) y=x-2;
if (x<-1 && x >-2) y=-x-2;
Console.Write("значение x="+x.ToString());
Console.Write("значение y="+y.ToString()); y
Console.Write("для повотора нажать y");
rep=char.Parse(Console.ReadLine());}
while(rep=='Y'||rep=='y');
}
}
}
Задача 2.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double a,
b,
c,
d,
min,
max,
raz;
char str;
do
{
min = 0;
max = 0;
Console.Clear();
Console.WriteLine("Введите значение переменной a");
a = double.Parse(Console.ReadLine ());
Console.WriteLine("Введите значение переменной b");
b = double.Parse(Console.ReadLine ());
Console.WriteLine("Введите значение переменной c");
c = double.Parse (Console.ReadLine ());
Console.WriteLine("Введите значение переменной d");
d = double.Parse(Console.ReadLine ());
min = a;
if (b < min) min = b;
if (c < min) min = c;
if (d < min) min = c;
max = a;
if (b > max) max = b;
if (c > max) max = c;
if (d > max) max = d;
raz = max- min;
Console.WriteLine("Минимальной число" +min);
Console.WriteLine("Максимальное число" +max);
Console.WriteLine("Разность максимального и минимального значения" +raz);
Console.WriteLine("Для повторного вычисления нажмите Y || y");
str = char.Parse(Console.ReadLine());
}
while (str == 'Y'|| str == 'y');
}
}
}
Задача 3.
using System;
using System.Collections;
using System.Linq;
using System.Text;
namespace Control
{
class Program
{
static void Main(string[] args)
{
int m = 0, n=0, a=0, b=0, dlina;
bool flag, wor = false;
string rep;
ArrayList chet = new ArrayList();
do
{
Console.Clear();
Console.Write("Введите число строк массива: ");
do
{
wor = false;
try
{
m = int.Parse(Console.ReadLine());
}
catch
{
wor = true;
Console.Write("Ошибка ввода, введите заново: ");
}
} while (wor == true);
Console.Write("Введите число столбцов массива: ");
do
{
wor = false;
try
{
n = int.Parse(Console.ReadLine());
}
catch
{
wor = true;
Console.Write("Ошибка ввода, введите заново: ");
}
} while (wor == true);
int[,] mas = new int[m, n];
Console.Write("Введите начало интрервала для заполнения массива случайными числами: ");
do
{
wor = false;
try
{
a = int.Parse(Console.ReadLine());
}
catch
{
wor = true;
Console.Write("Ошибка ввода, введите заново: ");
}
} while (wor == true);
Console.Write("Введите конец интрервала для заполнения массива случайными числами: ");
do
{
wor = false;
try
{
b = int.Parse(Console.ReadLine());
}
catch
{
wor = true;
Console.Write("Ошибка ввода, введите заново: ");
}
} while (wor == true);
Console.WriteLine();
MyClass flow = new MyClass();
flow.Zapoln(mas, m, n, a, b);
flow.Vivod(mas, m, n);
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
flow.Opredelenie(mas[i, j], out flag);
if (flag == true)
chet.Add(mas[i, j]);
flag = false;
}
}
Console.WriteLine();
Console.Write("Четные элементы массива: ");
dlina = chet.Count;
flow.Vivod(chet, dlina);
Console.WriteLine("\n\n");
Console.Write("Повторить? (Y) ");
rep = Console.ReadLine();
} while (rep == "Y" || rep == "y" || rep == "У" || rep == "у");
}
}
class MyClass
{
public void Zapoln(int[,] mas, int m, int n, int a, int b)
{
Random gen = new Random();
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
mas[i, j] = gen.Next(a, b + 1);
}
public void Zapoln(int[][] mas, int m, int n, int a, int b)
{
Random gen = new Random();
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
mas[i][j] = gen.Next(a, b + 1);
}
public void Zapoln(int[,] mas, uint m, uint n, byte a, byte b)
{
Random gen = new Random();
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++)
mas[i,j] = gen.Next(a, b + 1);
}
public void Vivod(int[,] mas, int m, int n)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
Console.Write("{0,4}", mas[i, j]);
Console.WriteLine();
}
}
public void Opredelenie(int chislo, out bool flag)
{
if (chislo % 2 == 0)
flag = true;
else
flag = false;
}
public void Vivod(ArrayList chet, int i)
{
i--;
if (i == 0)
Console.Write("{0,4}", chet[i]);
else
{
Vivod(chet, i);
Console.Write("{0,4}", chet[i]);
}
}
}
}