c++中的乘法规则有人能写下代码给我看么

来源:百度知道 编辑:UC知道 时间:2024/06/14 04:34:18
就是这样
1x1=1 1x2=2....1x9=9
2x1=2......2x9=18
3x1=3...3x9=27
.
.
.
9x1=9...9x9=81
中间我就省了不写了`
有人会写出这样的代码吗?
要用for语句哦``拜托``

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
for(int row = 1; row <= 9; ++row)
{
for(int col = row; col <= 9; ++col)
cout << col << "×" << row << "=" << setw(2) << col * row << setw(3) << ' ';
cout << endl;
}
}

照你说的打成矩形了,而且有重复,比如1×2和2×1,
如果那是你需要的,那么稍微改下就可以了:

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
for(int row = 1; row <= 9; ++row)
{
for(int col = 1; col <= 9; ++col)
cout << col << "×" << row << "=" << setw(2) << col * row << setw(3) << ' ';
cout << endl;
}
}

#include <iostream>
using namespace std;

int main()
{
int i, j;