zoukankan      html  css  js  c++  java
  • C#采用双重循环实现A矩阵与B矩阵相加赋给C矩阵

    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("---------");
    }
    }
    }
  • 相关阅读:
    第十三周学习进度
    第二次冲刺阶段每日任务02
    第二次冲刺阶段每日任务01
    构建之法阅读笔记03
    找水王续
    第十二周学习进度
    找水王
    第十一周学习进度
    博客园的用户体验
    找水王1
  • 原文地址:https://www.cnblogs.com/h0906/p/11147855.html
Copyright © 2011-2022 走看看