我想使用清除函数与随机生成的值做一个矩阵乘法。因此,我希望使用函数(mat_def
)来生成矩阵,而另一个函数(mat_mul
)在矩阵作为参数发送时将它们相乘。矩阵 - 返回并传递参数C++
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
double mat_def(int n) //how to return the matrix
{
double a[n][n];
double f;
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
f= rand();
cout<<f ;
a[i][j]=f;
}
}
return 0;
}
double mat_mul(int n, double a[n][n], double b[n][n]) //how to send matrix as parameter
{
return 0;
}
int main()
{
/* initialize random seed: */
srand (time(NULL));
mat_def(10);
}
你的问题是什么?你想知道如何增加两个矩阵或其他东西? –
在C++中实现Matrix类有很多种方法。通常,查找重载':: operator []'并返回一个内部类的引用,该类也重载':: operator []',这样你就可以拥有真正的Matrix语法。 – jiveturkey
问题:在编译时已知矩阵的大小吗? 矩阵是否仅仅是方矩阵? –