就是这样
1x1=1 1x2=2....1x9=9
2x1=2......2x9=18
3x1=3...3x9=27
.
.
.
9x1=9...9x9=81
中间我就省了不写了`
有人会写出这样的代码吗?
參考答案:#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;
}
}