Synchronization of old projects
Part1
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,180 @@
|
||||
#region 练习题一
|
||||
int[,] arr1 = new int[100, 100];
|
||||
int index = 1;
|
||||
for (int i = 0; i < arr1.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr1.GetLength(1); j++)
|
||||
{
|
||||
arr1[i, j] = index;
|
||||
++index;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr1.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr1.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr1[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题二
|
||||
Console.WriteLine("练习题二");
|
||||
int[,] arr2 = new int[6, 6];
|
||||
Random r = new Random();
|
||||
Console.WriteLine(arr2.GetLength(0) / 2 + " " + arr2.GetLength(1) / 2);
|
||||
for (int i = 0; i < arr2.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr2.GetLength(1); j++)
|
||||
{
|
||||
if (i < arr2.GetLength(0)/2 && j+1 > arr2.GetLength(1)/2)
|
||||
arr2[i, j] = 0;
|
||||
else
|
||||
arr2[i, j] = r.Next(1, 11);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr2.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr2.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr2[i, j] + "\t");//+" "+ i + j +
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题三
|
||||
Console.WriteLine("练习题三");
|
||||
int[,] arr3 = new int[3, 3];
|
||||
int sum = 0;
|
||||
for (int i = 0; i < arr3.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr3.GetLength(1); j++)
|
||||
{
|
||||
arr3[i, j] = r.Next(1,11);
|
||||
if (i == j)
|
||||
sum += arr3[i, j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr3.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr3.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr3[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine(sum);
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题四
|
||||
Console.WriteLine("练习题四");
|
||||
int[,] arr4 = new int[3, 3];
|
||||
sum = 0;
|
||||
for (int i = 0; i < arr4.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr4.GetLength(1); j++)
|
||||
{
|
||||
arr4[i, j] = r.Next(1, 11);
|
||||
if (i == j)
|
||||
sum += arr4[i, j];
|
||||
else if (i + j == arr4.GetLength(1) - 1)
|
||||
sum += arr4[i, j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr4.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr4.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr4[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine(sum);
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题五
|
||||
Console.WriteLine("练习题五");
|
||||
int[,] arr5 = new int[5, 5];
|
||||
int max = 0;
|
||||
int min = 11;
|
||||
for (int i = 0; i < arr5.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr5.GetLength(1); j++)
|
||||
{
|
||||
arr5[i, j] = r.Next(1,11);
|
||||
if (arr5[i, j] > max)
|
||||
max = arr5[i, j];
|
||||
if (arr5[i, j] < min)
|
||||
min = arr5[i, j];
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < arr5.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr5.GetLength(1); j++)
|
||||
{
|
||||
Console.Write(arr5[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine(max);
|
||||
Console.WriteLine(min);
|
||||
#region clear
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region 练习题六
|
||||
Console.WriteLine("练习题六");
|
||||
int m = 5, n = 5;
|
||||
int[,] arr6 = new int[m, n];
|
||||
//bool类型的数组默认值是false,所以可以用来标记某个位置是否被访问过
|
||||
bool[] hang = new bool[m];
|
||||
bool[] lie = new bool[n];
|
||||
for (int i = 0; i < arr6.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr6.GetLength(1); j++)
|
||||
{
|
||||
arr6[i, j] = r.Next(0, 2);
|
||||
Console.Write(arr6[i, j] + "\t");
|
||||
if (arr6[i, j] == 1)
|
||||
{
|
||||
hang[i] = true;
|
||||
lie[j] = true;
|
||||
}
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
Console.WriteLine("分割");
|
||||
for (int i = 0; i < arr6.GetLength(0); i++)
|
||||
{
|
||||
for (int j = 0; j < arr6.GetLength(1); j++)
|
||||
{
|
||||
if (hang[i] == true || lie[j] == true)
|
||||
{
|
||||
arr6[i, j] = 1;
|
||||
}
|
||||
Console.Write(arr6[i, j] + "\t");
|
||||
}
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
#endregion
|
||||
Reference in New Issue
Block a user