Скачиваний:
53
Добавлен:
17.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, F = 1;

string str;

ConsoleKeyInfo r;

do

{

Console.Clear();

Console.WriteLine("Введите значиение переменной x");

do

{

str = Console.ReadLine();

} while (!double.TryParse(str, out x));

x = double.Parse(str);

Console.WriteLine("ВВедите значение переменной y");

do

{

str = Console.ReadLine();

} while (!double.TryParse(str, out x));

y = double.Parse(str);

if (x < y)

F = Math.Sin(x) + Math.Cos(y) * Math.Cos(y);

if (x == y)

F = Math.Log(Math.Abs(x));

if (x > y)

F = Math.Sin(x * x) + Math.Cos(y);

Console.WriteLine("Значение переменной F=" + F);

Console.WriteLine("При значении x=" + x);

Console.WriteLine("при значении y=" + y);

Console.WriteLine("Для выхода из программы нажмите Esc, для продолжения вычислений нажмите любую клавишу");

r = Console.ReadKey(true);

} while (r.Key != ConsoleKey.Escape);

}

}

}

Задача 2.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Контрольная_работа

{

class Program

{

static void Main(string[] args)

{

Console.BackgroundColor = ConsoleColor.Blue;

Console.ForegroundColor = ConsoleColor.Yellow;

double r, r1, x, y;

int flag;

char ch;

do

{

Console.WriteLine("Введите значение координаты x точки A(например, '2')");

x = double.Parse(Console.ReadLine());

Console.WriteLine("Введите значение координаты y точки A(например, '1')");

y = double.Parse(Console.ReadLine());

r = 4;

r1 = 2;

if (x * x + y * y <= r * r && x * x + y * y >= r1 * r1) flag = 1;

else flag = 0;

Console.WriteLine("A(" + x + "," + y + ")" + " Flag=" + flag);

Console.WriteLine("Повторить(Y/N) ?");

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

}

while (ch == 'Y' || ch == 'y');

}

}

}

Задача 3.

using System;

class Metodi

{

public int [,] Zapol(out int a,out int b)

{

int [,] mas;

int i,j,n,m;

Random gen=new Random();

Console.WriteLine("Введите количество строк массива: ");

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

Console.WriteLine("Введите количество столбцов массива");

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

a=n;b=m;

mas=new int[n,m];

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

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

mas[i,j]=gen.Next(-20,20);

return mas;

}

public void Vivod(int [,] mas,int n,int m)

{

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

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

Console.Write("{0,3}", mas[i,j]);

}

public void Sort(int n,int m,ref int [,] mas)

{

int k;

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

{

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

if (mas[i,j]<mas[i+1,j])

{

k=mas[i,j];mas[i,j]=mas[i+1,j];mas[i+1,j]=k;

}

}

}

}

class Program

{

public static void Main(string [] args)

{

int [,] mas;

char re;

do

{

int n, m;

Metodi met = new Metodi();

try

{

mas = met.Zapol(out n, out m);

met.Vivod(mas, n, m);

met.Sort(n, m, ref mas);

Console.WriteLine();

met.Vivod(mas, n, m);

}

catch (FormatException)

{ Console.WriteLine("Некорректно введены данные"); }

Console.WriteLine("Повторить расчёт? Y/N"); .

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

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

}

}

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