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

Задача 1.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Collections;

namespace AnnSpiridonova

{

class Program

{

static void Main(string[] args)

{

double a, b, c, d, min, max, r;

System.Console.BackgroundColor = ConsoleColor.Yellow;

System.Console.WriteLine("Программа анализа минимальных и максимальных значений чисел");

System.Console.WriteLine("Введите первое число");

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

System.Console.WriteLine("Введите второе число");

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

System.Console.WriteLine("Введите третье число");

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

System.Console.WriteLine("Введите четвертое число");

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

min=a;

if(min>b)

min=b;

if(min>c)

min=c;

if(min>d)

min=d;

System.Console.ForegroundColor = ConsoleColor.Black;

System.Console.WriteLine("Минимальное число:({0})", min);

max=b;

if(max<a)

max=a;

if(max<c)

max=c;

if(max<d)

max=d;

System.Console.WriteLine("Максимальное число:({0}) ", max);

r=max-min;

System.Console.WriteLine("Разность между минимальным и максимальным значением: ({0})", r);

System.Console.Beep(500, 1000);

System.Console.ReadLine();

}

}

}

Задача 2.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

start:;

Console.BackgroundColor = ConsoleColor.White;

Console.ForegroundColor = ConsoleColor.Black;

Console.Clear();

Console.WriteLine("Введите некоторое вещественно число");

double y;

string st;

char c;

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

if ((x < -1) || (x > 1))

y = 0;

else

if ((x <= 0) && (x >= -1))

y = x + 1;

else

y = Math.Sqrt(1 - x * x);

Console.WriteLine("Искомое значние функции Y(x)={0:f2}", y);

rep: ;

Console.WriteLine("Желате повторить вычисления еще раз Y/N");

st = Console.ReadLine();

if (st.Length > 1)

goto mis;

c=char.Parse(st);

if ((c == 'Y') || (c == 'y'))

{

Console.Clear();

goto start;

}

else

if ((c == 'N') || (c == 'n'))

goto finish;

else

goto mis;

mis: ;

Console.Beep(1600, 999);

Console.Beep(1600, 999);

Console.Beep(1600, 999);

Console.WriteLine("Неправильный формат ввода");

goto rep;

finish: ;

}

}

}

Задача 3

sing System;

using System.Collections.Generic;

using System.Collections;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Metod

{

int strok, stolb;

Random gen = new Random();

public Metod(int s, int ss)

{

strok = s;

stolb = ss;

}

public int Sozd()

{

return gen.Next(-10, 11);

}

public void Pol(int a, out bool r)

{

if (a > 0)

{

r = true;

}

else r = false;

}

public void Show(int[,] m)

{

Console.WriteLine("У нас получилась вот такая матрица размера {0}x{1} : \n", strok, stolb);

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

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

{

Console.BackgroundColor = ConsoleColor.Gray;

Console.ForegroundColor = ConsoleColor.Magenta;

Console.Write("{0, 4}", m[i, j]);

Console.ForegroundColor = ConsoleColor.White;

Console.BackgroundColor = ConsoleColor.Black;

}

}

public void Show(int[] s)

{

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

{ if (s[i]==0)

Console.Write("В {0,1}-ой строке нет положительных элементов", (i + 1));

if (s[i]==1)

Console.Write("В {0,1}-ой строке находится {1, 1} положительный элемент", (i + 1), s[i]);

if (s[i]>1 && s[i]<5)

Console.Write("В {0,1}-ой строке находится {1, 1} положительных элемента", (i+1), s[i]);

if (s[i] >= 5)

Console.Write("В {0,1}-ой строке находится {1, 1} положительных элементов", (i + 1), s[i]);

}

}

}

class Program

{

static void Main(string[] args)

{

Console.Title = "Волгин Кирилл Вариант 15";

int str, st;

int[,] mas;

int[] sum;

bool b;

ConsoleKeyInfo rep=new ConsoleKeyInfo();

do

{

Console.Clear();

Console.WriteLine("Сейчас мы с вами создадим матрицу");

try

{

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

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

Console.Write("Теперь введите количество столбцов: ");

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

Console.WriteLine("\n");

mas = new int[str, st];

sum = new int[str];

Metod ob = new Metod(str, st);

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

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

{

mas[i, j] = ob.Sozd();

}

ob.Show(mas);

Console.WriteLine();

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

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

{

ob.Pol(mas[i, j], out b);

if (b) sum[i]++;

}

ob.Show(sum);

}

catch

{

Console.BackgroundColor = ConsoleColor.Red;

Console.WriteLine("\n\a\aО-е-ей! Ошибка ввода!");

Console.BackgroundColor = ConsoleColor.Black;

}

Console.Write("\nНажмите Esc, если хотите завершить программу или любую другую клавишу в случае, если хотите попробовать еще раз");

rep = Console.ReadKey();

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

}

}

}

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