A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 李建龙 中级黑马   /  2013-6-10 21:03  /  1794 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文



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();
        }
    }
}


1 个回复

倒序浏览
值得学习ing!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马