首页 > Windows开发 > 详细

C#采用双重循环实现A矩阵与B矩阵相加赋给C矩阵

时间:2019-07-07 21:51:25      阅读:217      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace practise
{
class Program
{
static void Main(string[] args)
{
//矩阵A
int[,] A = { { 1, 2, 3 }, { 3, 4, 5 }, { 1, 3, 5 } };
//矩阵B
int[,] B = { { 1, 2, 3 }, { 3, 4, 5 }, { 2, 4, 6 } };
//矩阵C
int[,] C = new int[3, 3];
//循环给C赋值
for (int i = 0; i < A.GetLength(0); i++)
{
for (int j = 0; j < B.GetLength(1); j++)
{
C[i, j] = A[i, j] + B[i, j];
}
}
Print(A);
Print(B);
Print(C);
Console.Read();
}
static void Print(int[,] arry)
{
Console.WriteLine("---------");
for (int i = 0; i < arry.GetLength(0); i++)
{
for (int j = 0; j < arry.GetLength(1); j++)
{
Console.Write(arry[i, j]);
Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine("---------");
}
}
}

 

C#采用双重循环实现A矩阵与B矩阵相加赋给C矩阵

原文:https://www.cnblogs.com/h0906/p/11147855.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!