我是一名初学程序员,并且想做一些我最近一直在做的事情。
如何在C ++中乘以和添加向量矩阵?
此外,二进制加法是什么(以及如何做)?
我正在尝试使用STL
完成所有这些操作这是我到目前为止所得到的:
#include <iterator>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
int main () {
int *p;
int i, tam_arreglo;
vector<vector<int> > array2D;
cout << "Set the array size: " << endl;
cin >> tam_arreglo;
//create rows.
for(int i = 0; i < 5000; ++i) {
array2D.push_back(vector<int>());
}
//add columns to the rows.
for(int i = 0; i < 5000; i++) {
for(int j = 0; j < array2D.size(); j++) {
array2D[i].push_back(i + j);
}
}
srand( unsigned( time(NULL) ) );
//using dynamic memory for the matrix.
p = new (nothrow) int[i];
if (p == NULL) {
cout << "Error: failed to allocate memory ";
}
else {
cout << "The matrix is: " << endl;
for(int i = 0; i < tam_arreglo; i++) {
for(int j = 0; j < tam_arreglo; j++) {
array2D[i][j] = rand()%100;
cout << setw(4) << array2D[i][j];
}
cout << endl;
}
}
//free the allocated memory.
delete[] p;
}
tam_arreglo是数组的大小。