-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
123 lines (115 loc) · 2.65 KB
/
Program.cs
File metadata and controls
123 lines (115 loc) · 2.65 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//string[,] table = new string[2, 5];
// String.Empty
// table[0,0] table[0,1] table[0,2] table[0,3] table[0,4]
// table[1,0] table[1,1] table[1,2] table[1,3] table[1,4]
/*
table[1, 2] = "слово";
for (int rows = 0; rows < 2; rows++)
{
for (int columns = 0; columns <5; columns++)
{
Console.WriteLine($"{table[rows, columns]}");
}
}
*/
/*
int[,] matrix = new int[3, 4];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
Console.WriteLine($"{matrix[i, j]}"); // получится в один столбик
}
}
*/
/*
int[,] matrix = new int[3, 4];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
{
Console.Write($"{matrix[i, j]} "); // получится таблица
}
Console.WriteLine();
}
*/
// или
/*
int[,] matrix = new int[3, 4];
for (int i = 0; i < matrix.GetLength(0); i++)
{
for (int j = 0; j < matrix.GetLength(1); j++)
{
Console.Write($"{matrix[i, j]} "); // получится таблица
}
Console.WriteLine();
}
*/
/*
void PrintArray(int[,] matr)
{
for (int i = 0; i < matr.GetLength(0); i++)
{
for (int j = 0; j < matr.GetLength(1); j++)
{
Console.Write($"{matr[i, j]} ");
}
Console.WriteLine();
}
}
// генератор случайных чисел
void FillArray(int[,] matr)
{
for (int i = 0; i < matr.GetLength(0); i++)
{
for (int j = 0; j < matr.GetLength(1); j++)
{
matr[i,j] = new Random().Next(1,10); // [1; 10)
}
}
}
int[,] matrix = new int[3, 4];
PrintArray(matrix);
FillArray(matrix);
Console.WriteLine(); // для прослойки
PrintArray(matrix);
*/
// Факториал
/*
int Factorial(int n)
{
// 1! = 1
// 0! = 1
if (n == 1) return 1;
else return n * Factorial(n-1);
}
for (int i = 1; i <40; i++)
{
//Console.WriteLine(Factorial(3));
Console.WriteLine($"{i}!={Factorial(i)}"); //для контроля больших факториалов до 17
}
*/
double Factorial(int n) // для факториалов больше 17
{
if (n == 1) return 1;
else return n * Factorial(n-1);
}
for (int i = 1; i <40; i++)
{
//Console.WriteLine(Factorial(3));
Console.WriteLine($"{i}!={Factorial(i)}");
}
// Фибонaччи
//f(1) = 1
//f(2) = 1
// f(n) = f(n-1) + f(n-2)
int Fibonacci(int n) // для больших чисел использовать double
{
if (n == 1 || n ==2) return 1;
else return Fibonacci(n-1) + Fibonacci(n-2);
}
for (int i=1; i<50; i++)
{
//Console.WriteLine(Fibonacci(i));
Console.WriteLine($"f({i}) = {Fibonacci(i)}"); //для контроля больших чисел
}