-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
82 lines (66 loc) · 2.69 KB
/
Program.cs
File metadata and controls
82 lines (66 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Задача 19: Напишите программу, которая принимает на вход пятизначное число и проверяет, является ли оно палиндромом.
// 14212 -> нет
// 23432 -> да
// 12821 -> да
Console.WriteLine("Задача 19");
Console.Write("Введите число: ");
string? number = Console.ReadLine();
void CheckingNumber(string number){
if (number[0]==number[4] || number[1]==number[3]){
Console.WriteLine($"Ваше число: {number} - палиндром.");
}
else Console.WriteLine($"Ваше число: {number} - НЕ палиндром.");
}
if (number!.Length == 5){
CheckingNumber(number);
}
else Console.WriteLine($"Введи правильное число");
// Задача 21: Напишите программу, которая принимает на вход координаты двух точек и находит расстояние между ними в 3D пространстве.
// A (3,6,8); B (2,1,-7), -> 15.84
// A (7,-5, 0); B (1,-1,9) -> 11.53
Console.WriteLine("\n Задача 21");
int x1 = Coordinate("x", "A");
int y1 = Coordinate("y", "A");
int z1 = Coordinate("z", "A");
int x2 = Coordinate("x", "B");
int y2 = Coordinate("y", "B");
int z2 = Coordinate("z", "B");
int Coordinate(string coorName, string pointName)
{
Console.Write($"Введите координату {coorName} точки {pointName}: ");
return Convert.ToInt16(Console.ReadLine());
}
double Decision(double x1, double x2,
double y1, double y2,
double z1, double z2){
return Math.Sqrt(Math.Pow((x2-x1), 2) +
Math.Pow((y2-y1), 2) +
Math.Pow((z2-z1), 2));
}
double segmentLength = Math.Round (Decision(x1, x2, y1, y2, z1, z2), 2 );
Console.WriteLine($"Длина отрезка {segmentLength}");
//Задача 23: Напишите программу, которая принимает на вход число (N) и выдаёт таблицу кубов чисел от 1 до N.
// 3 -> 1, 8, 27
// 5 -> 1, 8, 27, 64, 125
Console.WriteLine("\n Задача 23");
Console.Write("Введите число: ");
int cube = Convert.ToInt32(Console.ReadLine());
void Cube(int[] cube){
int counter = 0;
int length = cube.Length;
while (counter < length){
cube[counter] = Convert.ToInt32(Math.Pow(counter, 3));
counter++;
}
}
void PrintArry(int[] coll){
int count = coll.Length;
int index = 0;
while(index < count){
Console.Write(coll[index]+ " ");
index++;
}
}
int[] array = new int[cube+1];
Cube(array);
PrintArry(array);