主题:[讨论]运行到一半就停了
题目是求二维数组的对角线之和
using System;
using System.Collections.Generic;
using System.Text;
namespace planar_array
{
class Program
{
static void Main()
{
int row, cols;
int value;
int sum=0;
int row_i,cols_j;
int[,] ARRAY;
Console.WriteLine("请输入行数:");
row = int.Parse(Console.ReadLine());
Console.WriteLine("请输入列数:");
cols = int.Parse(Console.ReadLine());
ARRAY = new int[row, cols];
Console.WriteLine("为数组输入数值:");
for (row_i = 0; row_i < row; row_i++)
{
for (cols_j = 0; cols_j < cols; cols_j++)
{
Console.WriteLine("第{0}行,第{1}列:", row_i + 1, cols_j + 1);
value=int.Parse(Console.ReadLine());
ARRAY[row_i, cols_j] = value;
}
}
for (row_i = 0; row_i < row; row++)
sum = sum + (ARRAY[row_i, row_i] + ARRAY[row_i, (cols - row_i)]);
Console.WriteLine("显示数组结果:");
for (row_i = 0; row_i < row; row_i++)
{
for (cols_j = 0; cols_j < cols; cols_j++)
{
Console.Write("{0}", ARRAY[row_i, cols_j]);
if (cols == 3)
Console.WriteLine("\n");
}
}
Console.WriteLine("对角线之和:");
Console.WriteLine("{0}",sum);
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace planar_array
{
class Program
{
static void Main()
{
int row, cols;
int value;
int sum=0;
int row_i,cols_j;
int[,] ARRAY;
Console.WriteLine("请输入行数:");
row = int.Parse(Console.ReadLine());
Console.WriteLine("请输入列数:");
cols = int.Parse(Console.ReadLine());
ARRAY = new int[row, cols];
Console.WriteLine("为数组输入数值:");
for (row_i = 0; row_i < row; row_i++)
{
for (cols_j = 0; cols_j < cols; cols_j++)
{
Console.WriteLine("第{0}行,第{1}列:", row_i + 1, cols_j + 1);
value=int.Parse(Console.ReadLine());
ARRAY[row_i, cols_j] = value;
}
}
for (row_i = 0; row_i < row; row++)
sum = sum + (ARRAY[row_i, row_i] + ARRAY[row_i, (cols - row_i)]);
Console.WriteLine("显示数组结果:");
for (row_i = 0; row_i < row; row_i++)
{
for (cols_j = 0; cols_j < cols; cols_j++)
{
Console.Write("{0}", ARRAY[row_i, cols_j]);
if (cols == 3)
Console.WriteLine("\n");
}
}
Console.WriteLine("对角线之和:");
Console.WriteLine("{0}",sum);
}
}
}