计算4×4矩阵的次对角线元素之和。(C#语言)

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

namespace Cjing
{
    class Program
    {
        static void Main(string[] args)
        {
           
                int[,] td = new int[4, 4] {
                {1,2,3,4},
                {10,12,14,16},
                {18,20,22,24},
                {6,7,8,9}};
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Console.Write(td[i,j]+"  ");
                }
                Console.WriteLine();

            }
         
            int sum = 0;
            for (int i = 0; i<4; i++)
                {
                sum += td[i, 4-1-i];
                      
                }
             
            Console.WriteLine(sum);
            Console.ReadLine();
        }
        
     
    }
}

 

你可能感兴趣的:(C#,c#)