C++程序制表_i++

效果图如上,利用循环和转义字符\t,记住外层循环控制行,内层循环控制列就OK。

#include <iostream>
#include <string>
using namespace std;
int main() {
string stu_names[]{ "刘备","关羽","张飞" };
string course_names[]{ "语文","数学","英语" };
const int ROW = 3;
const int COL = 3;
double scores[ROW][COL];
for (int i = 0; i < ROW; i++) {
for (int j = 0; j < COL; j++) {
cout << stu_names[i] << "的" << course_names[j] << "成绩:";
cin >> scores[i][j];
}
}
cout << '\t';
for (int i = 0; i < COL; i++) {
cout << course_names[i] << '\t';
}
cout << endl;
for (int i = 0; i < ROW; i++) {
cout << stu_names[i] << '\t';
for (int j = 0; j < COL; j++) {
cout << scores[i][j] << "\t";
}
cout << endl;
}
system("pause");
return 0;
}