Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Xml.Serialization;
- namespace Practice_n3_and_n4
- {
- class Practice_n3
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.Unicode;
- // Task_4();
- Task_6();
- }
- public static void Task_4()
- {
- Console.Write("Введите число а: ");
- int a = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число b: ");
- int b = Convert.ToInt32(Console.ReadLine());
- for (int i = (a % 3 == 0 ? a : ((a % 3 == 1) ? a + 2 : a + 1)); i <= b; i += 3)
- {
- Console.Write((i % 2 == 0) ? i + " " : "");
- }
- }
- public static void Task_6()
- {
- Console.Write("Введите число а: ");
- double a = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите число b: ");
- double b = Convert.ToDouble(Console.ReadLine());
- Console.Write("Введите число h: ");
- double h = Convert.ToDouble(Console.ReadLine());
- double eps = 1E-12;
- double y;
- Console.WriteLine("Таблица значений функции Func(x, y):");
- for (double x = a; Math.Abs(x - b) >= eps; x += h)
- {
- Func(x, out y);
- Console.WriteLine("{0:f3}\t{1:f3}", x, y);
- }
- }
- public static void Func(double x, out double y)
- {
- double eps = 1E-12;
- y = 0;
- if (x + 2 <= 1 - eps)
- {
- y = Power(x, 2);
- }
- else if (x + 2 > 1 + eps && x + 2 < 10 - eps)
- {
- y = 1 / (x + 2);
- }
- else if (x + 2 >= 10 + eps)
- {
- y = x + 2;
- }
- }
- public static double Power(double num, byte n)
- {
- double res = 1;
- while (num > 0)
- {
- if (n % 2 == 1) res *= num;
- num *= num;
- n /= 2;
- }
- return res;
- }
- }
- class Practice_n4
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.Unicode;
- // Task_6();
- Task_7();
- }
- public static void Task_6()
- {
- Console.Write("Введите число из условия: ");
- int number = Convert.ToInt32(Console.ReadLine());
- Pair<int, int> res = MinAndMaxDels(number);
- Console.WriteLine("Ответ: {0}", res.first + res.second);
- }
- public static Pair<int, int> MinAndMaxDels(int num)
- {
- int min = 1, max = num;
- bool flag = true;
- for (int i = 2; i <= Math.Sqrt(num); ++i)
- {
- if (CountDel(i) == 2 && num % i == 0)
- {
- if (flag)
- {
- min = i;
- max = i;
- flag = false;
- }
- else
- {
- max = i;
- }
- }
- }
- Pair<int, int> res = Pair<int, int>.MakePair(min, max);
- return res;
- }
- public static int CountDel(int num)
- {
- int cnt = 2;
- for (int i = 2; i < Math.Sqrt(num); ++i)
- {
- if (num % i == 0) ++cnt;
- }
- return cnt;
- }
- public static void Task_7()
- {
- Console.Write("Введите число N: ");
- int number = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число C: ");
- int c = Convert.ToInt32(Console.ReadLine());
- while (!IsDigitSumEqualsC(number, c))
- {
- number++;
- }
- Console.WriteLine("Найденное число: {0}", number);
- }
- public static bool IsDigitSumEqualsC(int num, int c)
- {
- int sum = 0;
- while (num > 0)
- {
- sum += num % 10;
- num /= 10;
- }
- if (sum % c == 0) return true;
- return false;
- }
- }
- class Pair<T, U> : Practice_n4
- {
- public T first;
- public U second;
- public Pair(T first, U second)
- {
- this.first = first;
- this.second = second;
- }
- public Pair<T, U> CopyPair(Pair<T, U> p)
- {
- Pair<T, U> newPair = new Pair<T, U>(p.first, p.second);
- return newPair;
- }
- public static Pair<T, U> MakePair(T first, U second)
- {
- Pair<T, U> newPair = new Pair<T, U>(first, second);
- return newPair;
- }
- }
- class Practice_n5
- {
- public static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.Unicode;
- Practice_n5.Task_4();
- }
- public static double power(double num, byte n)
- {
- double res = 1;
- while (num > 0)
- {
- if (n % 2 == 1) res *= num;
- num *= num;
- n /= 2;
- }
- return res;
- }
- public static void Task_2a()
- {
- Console.Write("Введите число а: ");
- int a = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число b: ");
- int b = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число h: ");
- int h = Convert.ToInt32(Console.ReadLine());
- byte number = 1;
- for (int i = a; i <= b; i += h)
- {
- Console.Write("{0} ", Practice_n5.power(i, number));
- number++;
- }
- }
- public static void Task_2b()
- {
- Console.Write("Введите число а: ");
- int a = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число b: ");
- int b = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число h: ");
- int h = Convert.ToInt32(Console.ReadLine());
- double sum = 0;
- byte number = 1;
- for (int i = a; i <= b; i += h)
- {
- sum += Practice_n5.power(i, number);
- number++;
- }
- Console.WriteLine("{0}", sum);
- }
- public static void Task_2c()
- {
- Console.Write("Введите число а: ");
- int a = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число b: ");
- int b = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Все подходящие тройки:");
- for (int i = a; i <= b - 2; ++i)
- {
- for (int j = i + 1; j <= b - 1; ++j)
- {
- for (int k = j + 1; k <= b; ++k)
- {
- if (Practice_n5.power(i, 2) + Practice_n5.power(j, 2) == Practice_n5.power(k, 2))
- {
- Console.WriteLine("{0} {1} {2}", i, j, k);
- }
- }
- }
- }
- }
- public static void Task_2d()
- {
- Console.Write("Введите число а: ");
- int a = Convert.ToInt32(Console.ReadLine());
- byte n = 1;
- while (!(a >= Practice_n5.power(2, (byte) (n - 1)) && a < Practice_n5.power(2, n)))
- {
- n++;
- }
- Console.WriteLine("Искомая степень n = {0}", n);
- }
- public static void Task_3()
- {
- Console.Write("Введите число n: ");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.Write("Введите число x: ");
- double x = Convert.ToDouble(Console.ReadLine());
- Console.WriteLine("Ответ: {0}", ChainDivision(n, x));
- }
- public static double ChainDivision(int n, double x, int i = 1)
- {
- if (i < n)
- {
- return x / (i + ChainDivision(n, x, ++i));
- }
- return i + x;
- }
- public static void Task_4()
- {
- Console.Write("Введите количество строк со звездочками: ");
- int n = Convert.ToInt32(Console.ReadLine());
- PrintStairs(n);
- }
- public static void PrintStairs(int n)
- {
- Practice_n5.PrinStarLine(n);
- if (n > 1)
- {
- PrintStairs(n - 1);
- }
- }
- public static void PrinStarLine(int n)
- {
- for (int i = 0; i < n; ++i)
- {
- Console.Write("*");
- }
- Console.WriteLine("");
- }
- }
- class Practice_n7
- {
- /*public static void Task_4()
- {
- Console.Write("Введите размерность квадратной матрицы: ");
- int n = Convert.ToInt32(Console.ReadLine());
- int[,] mas = InitMas(n);
- int[] res = new int[n];
- for (int i = 0; i < mas.GetLength(0); ++i)
- {
- int max = mas[0, i];
- for (int j = 1; j < mas.GetLength(1); ++j)
- {
- if (mas[j, i] > max) max = mas[j, i];
- }
- res[i] = max;
- }
- PrintResultArray(res);
- }*/
- /*public static int[,] InitMas(int n)
- {
- int[,] mas = new int[n, n];
- for (int i = 0; i < mas.GetLength(0); ++i)
- {
- for (int j = 0; j < mas.GetLength(1); ++j)
- {
- Console.Write("mas[{0}, {1}] = ", i, j);
- mas[i, j] = Convert.ToInt32(Console.ReadLine());
- }
- }
- return mas;
- }*/
- public static void PrintResultArray(int[] res)
- {
- for (int i = 0; i < res.Length; ++i)
- {
- Console.Write("{0} ", res[i]);
- }
- }
- public static void Task_5()
- {
- Console.Write("Введите количество элементов в массиве: ");
- int n = Convert.ToByte(Console.ReadLine());
- Console.Write("Введите элемент, который нужно добавлять: ");
- int x = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введите элементы массива: ");
- int[] mas = InitMas(n);
- for (byte i = 1; i <= n; ++i)
- {
- if (mas[i - 1] % (i + 1) == 0)
- {
- ShiftMas(mas, i, ref n);
- mas[i] = x;
- ++i;
- }
- }
- PrintMas(mas, n);
- }
- public static int[] InitMas(int n)
- {
- int[] mas = new int[2 * n];
- for (int i = 0; i < n; ++i)
- {
- mas[i] = Convert.ToInt32(Console.ReadLine());
- }
- return mas;
- }
- public static void ShiftMas(int[] mas, int index, ref int n)
- {
- for (int i = n; i >= index; --i)
- {
- mas[i] = mas[i - 1];
- }
- ++n;
- }
- public static void PrintMas(int[] mas, int n)
- {
- for (int i = 0; i < n; ++i)
- {
- Console.Write("{0} ", mas[i]);
- }
- }
- public static void Task_6()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement