using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[4, 4];
int c1, c2, i, j;
Console.WriteLine("求矩阵对角线元素的和为\n");
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
a[i,j]=i*4+j ;
}
}
Console.WriteLine("原始矩阵为\n");
for (i = 0; i < 4; i++)
{
for (j = 0; j < 4; j++)
{
Console.Write("{0,4}",a[i,j]);
}
Console.WriteLine();
}
c1=0;
c2=0;
for (i = 0; i < 4; i++)
{
c1=c1+a[i,i];
c2=c2+a[i,3-i];
}
Console.WriteLine("矩阵对角线元素的和为{0},{1}",c1,c2);
Console.Read();
}
}
}