对称矩阵 一个简单的小把戏

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
while (true)
{


Console.WriteLine("请输入矩阵的秩!!");
int M = int.Parse(Console.ReadLine());
string[,] a = new string[M, M];
Random r = new Random(System.Guid.NewGuid().GetHashCode());

for (int i = 0; i < M; i++)
{
for (int j = i; j < M; j++)
{
a[i, j] = r.Next(1, 100).ToString();
}
}

for (int i = 0; i < M; i++)
{
for (int j = 0; j < i; j++)
{
a[i, j] = a[j, i];

}
}

for (int i = 0; i < M; i++)
{
for (int j = 0; j < M; j++)
{
if (a[i, j].ToString().Length == 1)
{
a[i, j] = "0" + a[i, j];
}
Console.Write(a[i, j] + " ");
}
Console.WriteLine();
}
}
Console.ReadKey();
}
}
}

原文地址:https://www.cnblogs.com/kexb/p/4875994.html