using System;
class Program
{
static void Main(string[] args)
{
int[,] array = new int[5, 5];
int i, j, k;
int max, min, max_row, max_col, min_row, min_col, sum = 0;
string str1, str2 = "";
Console.WriteLine("请输入五行数据,每行五个数据,以空格隔开,每行输入完之后回车(输入格式不对会出错):");
for (i = 0; i < 5; i++)
{
str1 = Console.ReadLine();
j = 0;
k = 0;
while (j < str1.Length)
{
if (str1[j] != ' ')
str2 += str1[j];
else
{
array[i, k++] = int.Parse(str2);
str2 = "";
}
j++;
}
array[i, k] = int.Parse(str2);
str2 = "";
}
max = min = array[0,0];
max_row = max_col = 1;
min_row = min_col = 1;
for(i=0; i < 5; i++)
for (j = 0; j < 5; j++)
{
if (max < array[i, j])
{
max = array[i, j];
max_row = i + 1;
max_col = j + 1;
}
if (min > array[i, j])
{
min = array[i, j];
min_row = i + 1;
min_col = j + 1;
}
}
for (i = 0; i < 5; i++)
sum += array[i, i];
Console.WriteLine("最大数为:{0},位置是:第{1}行,第{2}列", max, max_row, max_col);
Console.WriteLine("最小数为:{0},位置是:第{1}行,第{2}列", min, min_row, min_col);
Console.WriteLine("对角线上的元素之和为:{0}", sum);
}
}
刚刷新已经被人抢先,和楼上差不多,不过楼上少写了一句 Console.ReadLine();
no time.