c#实现矩阵的转置,相乘等

比较简单,适合 初学者

题目:

定义矩阵类,完成矩阵的产生,转置和相乘(控制台程序)

步骤:

1.可以新创建一个控制台程序,也可在原工程中添加新类

右键工程名

ADD->new items->class,名称为Matrix

具体的代码如下:

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

namespace ClassTest
{
    class Matrix
    {
        private double[,] matrix;//一个二维数组,保存矩阵中的值
        private int col;//矩阵的列数
        private int row;//矩阵的行数
        private string name;//矩阵的名字
        //构造函数
        public Matrix()
        {

        }
        public Matrix(int row,int col)
        {
            this.col = col;
            this.row = row;
            this.name = "";
            this.matrix = new double[row, col];
        }
        public Matrix(int row,int col,string name)
        {
            this.col = col;
            this.row = row;
            this.name=name;
            this.matrix=new double[row,col];
        }
        public Matrix(int row, int col, double[] data)
        {
            this.col = col;
            this.row = row;
            this.name = "";
            this.matrix = new double[row, col];
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    this.matrix[i,j] = data[i * col + j];
                }
            }
        }
        public

  • 1
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值