Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace main {
- class Program {
- static private double f_1(double x1, double y1, double x2, double y2) {
- return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2));
- }
- static private bool t_1(double a, double b, double c) {
- return ((a < b + c) && (b < a + c) && (c < a + b));
- }
- static private int f_2(int n) {
- int s = 0;
- while (n != 0) {
- s += n % 10;
- n /= 10;
- }
- return s;
- }
- static private double f_3(double x) {
- if (Math.Abs(x) < 2)
- return Math.Sqrt(5 * x * x + 5);
- else if (Math.Abs(x) >= 10)
- return 0;
- else
- return Math.Abs(x) / Math.Sqrt(5 * x * x + 5);
- }
- static private void f_3(double x, out double y) {
- if (Math.Abs(x) < 2)
- y = Math.Sqrt(5 * x * x + 5);
- else if (Math.Abs(x) >= 10)
- y = 0;
- else
- y = Math.Abs(x) / Math.Sqrt(5 * x * x + 5);
- }
- static private int Akkerman_4(int n, int m) {
- if (n == 0)
- return m + 1;
- else if (n != 0 && m == 0)
- return Akkerman_4(n - 1, 1);
- else
- return Akkerman_4(n - 1, Akkerman_4(n, m - 1));
- }
- static private void f_5(int n) {
- string lun = "лунатиков", lun_1 = "лунатиков";
- string g1 = "жили", g2 = "ворочались", g3 = "осталось";
- if ((n / 10) % 10 != 1) {
- if (n % 10 == 2) {
- lun_1 = "лунатик";
- g3 = "остался";
- }
- if (n % 10 == 5) {
- lun_1 = "лунатика";
- }
- if (n % 10 == 1) {
- lun = "лунатик";
- g1 = "жил";
- g2 = "ворочался";
- }
- else if (n % 10 >= 2 && n % 10 <= 4) {
- lun = "лунатика";
- if (n % 10 != 2)
- lun_1 = "лунатика";
- }
- }
- Console.WriteLine("{0} {1} {2} на луне", n, lun, g1);
- Console.WriteLine("{0} {1} {2} во сне", n, lun, g2);
- if (n == 1) {
- Console.WriteLine("Последний лунатик упал с луны во сне");
- Console.WriteLine("И больше лунатиков не стало на луне");
- return;
- }
- else {
- Console.WriteLine("Один из лунатиков упал с луны во сне");
- Console.WriteLine("{0} {1} {2} на луне", n - 1, lun_1, g3);
- f_5(n - 1);
- }
- }
- static private void f_6(int n, int del = 2, int m = -1, int r = 0, int[] arr = null) {
- if (m == -1) {
- m = n;
- arr = new int[100];
- }
- if (n == 1) {
- if (r == 1)
- return;
- for (int i = 0; i < r; ++ i) {
- Console.Write("{0}", arr[i]);
- if (i != r - 1)
- Console.Write("*");
- }
- Console.WriteLine("={0}", m);
- return;
- }
- for (int i = del; i <= n; ++ i) {
- if (n % i == 0) {
- arr[r] = i;
- f_6(n / i, i, m, r + 1, arr);
- }
- }
- }
- public static void Main(string[] args) {
- goto n6;
- //n1
- Console.WriteLine("Задание 1:");
- double[,] coords = new double[3,2];
- for (int i = 0; i < 3; ++ i) {
- Console.Write("x{0}=", i + 1);
- coords[i, 0] = Convert.ToDouble(Console.ReadLine());
- Console.Write("y{0}=", i + 1);
- coords[i, 1] = Convert.ToDouble(Console.ReadLine());
- }
- double a = f_1(coords[0, 0], coords[0, 1], coords[1, 0], coords[1, 1]);
- double b = f_1(coords[1, 0], coords[1, 1], coords[2, 0], coords[2, 1]);
- double c = f_1(coords[2, 0], coords[2, 1], coords[0, 0], coords[0, 1]);
- if (t_1(a, b, c))
- Console.WriteLine("Треугольник с вершинами в заданных точках существует");
- else
- Console.WriteLine("Треугольник с вершинами в заданных точках не существует");
- //
- n2:
- //n2
- Console.WriteLine("Задание 2:");
- Console.Write("a=");
- int x = Convert.ToInt32(Console.ReadLine());
- Console.Write("b=");
- int y = Convert.ToInt32(Console.ReadLine());
- if (x > y) {
- int tmp = x;
- x = y;
- y = tmp;
- }
- Console.WriteLine("1:");
- for (int i = x; i <= y; ++ i)
- Console.WriteLine("\t{0}: {1}", i, f_2(i));
- Console.WriteLine("2:");
- Console.Write("c=");
- int z = Convert.ToInt32(Console.ReadLine());
- for (int i = x; i <= y; ++ i)
- if (f_2(i) == z)
- Console.WriteLine("\t{0}: {1}", i, z);
- Console.WriteLine("3:");
- for (int i = x; i <= y; ++ i)
- if (f_2(i) % 2 != 0)
- Console.WriteLine("\t{0}: {1}", i, f_2(i));
- Console.WriteLine("4:");
- Console.Write("A=");
- z = Convert.ToInt32(Console.ReadLine());
- x = z - 1;
- for (; x > 0; -- x) {
- if (f_2(z) == f_2(x)) {
- Console.WriteLine("{0}", x);
- break;
- }
- }
- if (x == 0)
- Console.WriteLine("Не существует");
- //
- n3:
- //n3
- Console.WriteLine("Задание 4:");
- Console.Write("a=");
- a = Convert.ToDouble(Console.ReadLine());
- Console.Write("b=");
- b = Convert.ToDouble(Console.ReadLine());
- Console.Write("h=");
- double h = Convert.ToDouble(Console.ReadLine());
- if (a > b) {
- double tmp = a;
- a = b;
- b = tmp;
- }
- for (double i = a; i <= b; i += h)
- Console.WriteLine("x={0}; y = {1}", i, f_3(i));
- //
- n4:
- //n4
- Console.WriteLine("Задание 4:");
- Console.Write("n=");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.Write("m=");
- int m = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine(Akkerman_4(n, m));
- //
- n5:
- //n5
- Console.WriteLine("Задание 5:");
- Console.Write("n=");
- n = Convert.ToInt32(Console.ReadLine());
- f_5(n);
- //
- n6:
- Console.WriteLine("Задание 6:");
- Console.Write("n=");
- n = Convert.ToInt32(Console.ReadLine());
- f_6(n);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement