vector 乘法表
时间: 2023-10-19 15:33:15 浏览: 91
乘法表问题
引用中的代码展示了使用vector实现打印乘法表的方法。首先,定义了一个二维vector,大小为9×9。然后,使用嵌套循环来遍历二维vector,将每个位置的元素设置为对应的乘法结果。最后,再次使用嵌套循环将二维vector中的元素打印出来,形成乘法表的效果。
下面是使用vector实现的乘法表的代码:
```
#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
int main() {
int j = 0;
vector<vector<int>> vec(9, vector<int>(0));
for (int i = 0; i < 9; i++) {
for (j = 0; j <= i; j++) {
vec[i].push_back((i + 1) * (j + 1));
}
}
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j <= i; j++) {
cout << (i + 1) << "*" << (j + 1) << "=" << setw(2) << vec[i][j << " ";
}
cout << endl;
}
return 0;
}
```
这段代码首先定义了一个二维vector,大小为9×9,并使用嵌套循环将每个位置的元素设置为对应的乘法结果。然后,再次使用嵌套循环将二维vector中的元素打印出来,形成乘法表的效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [matlab矩阵的乘法代码书写-LinAlg:用于异构超级计算机的小型可扩展矩阵库](https://download.csdn.net/download/weixin_38632825/19382155)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Python中四种样式的99乘法表](https://blog.csdn.net/weixin_39639568/article/details/110073810)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [用vector打印乘法口诀表](https://blog.csdn.net/tomatolee221/article/details/90695166)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文