Скачиваний:
66
Добавлен:
15.04.2018
Размер:
47.1 Кб
Скачать

Задача 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 ConsoleApplication

{

class Program

{

public static void Main(string[] args)

{ double [,] b;

int m, n;

char r;

do{

try{

Console.WriteLine("Введите целочисленное значение параметра m ");

m = int.Parse(Console.ReadLine());

Console.WriteLine("Введите целочисленное значение параметра n ");

n = int.Parse(Console.ReadLine());

}

catch{Console.WriteLine("Исходные данные введены неверно,нужно вводить целые положительные числа.");

}

b = new double[m, n];

for (int i = 0; i < m; i++)

for (int j = 0; j < n; j++)

FunBanana.Заполнение(b,m,n);

FunBanana.Печать(b,m,n);

FunBanana.Копирование (out ArrayList a);

FunBanana.Печать2(a);

Console.ReadLine();

Console.WriteLine("Завершить программу? Y/N");

r= char.Parse(Console.ReadLine());

} while (r=='Y'|| r=='y');

}

}

}

Задача 3.

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class MyMethod

{

public static void Rand(double[,] mas, int n, int m)

{

Random gen = new Random();

for (int i = 0; i < n; i++)

for (int j = 0; j < m; j++)

mas[i, j] = (double)gen.Next(-12, 22)/10;

}

public static void Print(double[,] mas, int n, int m)

{

for (int i = 0; i < n; i++, Console.WriteLine())

for (int j = 0; j < m; j++) Console.Write("{0,8:f2}", mas[i,j]);

}

public static double[] Prostoe(double[,] mas, int n, int m)

{

int l = 0;

double[] k;

for (int i = 0; i < n; i++)

for (int j = 0; j < m; j++)

{

if (mas[i, j] > 0)

l++;

}

k = new double[l];

for (int i = 0, x=0; i < n; i++)

for (int j = 0; j < m; j++)

{

if (mas[i, j] > 0)

{ k[x] = mas[i, j]; x++; }

}

return k;

}

public static void Print(double[] a, int n)

{

for (int i = 0; i < n; i++)

Console.Write("{0,8:f2}", a[i]);

}

}

class Program

{

static void Main(string[] args)

{

int n, m;

double[] a;

ConsoleKeyInfo клавиша;

do

{

Console.Clear();

Console.Write("Кол-во строк: ");

n = int.Parse(Console.ReadLine());

Console.Write("\nКол-во столбцов: ");

m = int.Parse(Console.ReadLine());

double[,] mas = new double[n, m];

MyMethod.Rand(mas, n, m);

Console.WriteLine("\n Исходный массив:");

MyMethod.Print(mas, n, m);

a=MyMethod.Prostoe(mas, n, m);

Console.WriteLine("\n Сформированный массив:");

MyMethod.Print(a, n);

Console.WriteLine("\n Для выходанажмите ESC");

клавиша = Console.ReadKey(true);

} while (клавиша.Key != ConsoleKey.Escape);

}

}

}

Соседние файлы в папке Программы