gpt4 book ai didi

c++ - 我的 4 x 4 矩阵没有打印出 C++

转载 作者:行者123 更新时间:2023-11-27 23:49:41 26 4
gpt4 key购买 nike

<分区>

所以我不确定我做错了什么。我知道这将是一些小而简单的事情,但我确实需要一点帮助。大多数情况下它只打印出每行的第一个数字,之后它只打印出 0。可能只是因为我整天盯着电脑,压力导致我的大脑无法正常工作,但任何帮助都会很棒。我知道大多数人使用 i 和 j,但我喜欢用 r 代表行,用 c 代表列。

#include <iostream>

using namespace std;

int main() {

int m1[4][4] = {(1, 2, 3, 4), (4, 3, 2, 1), (1, 2, 3, 4), (4, 3, 2, 1)};
int m2[4][4] = {(0, 0, 0, 0), (1, 1, 1, 1), (2, 2, 2, 2), (3, 3, 3, 3)};
int m3[4][4] = {(5, 8, 2, 5), (4, 7, 1, 4), (6, 9, 3, 6), (4, 5, 6, 4)};
int m4[4][4] = {(1, 3, 7, 9), (2, 6, 8, 4), (7, 8, 9, 6), (1, 2, 3, 4)};

//print matrix 1
cout << "Matrix 1: " << endl;
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 4; c++) {
cout << m1[r][c] << " ";
}
cout << endl;
}
cout << endl << endl;


//print natrix 2
cout << "Matrix 2: " << endl;
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 4; c++) {
cout << m2[r][c] << " ";
}
cout << endl;
}
cout << endl << endl;

//print matrix 3
cout << "Matrix 3: " << endl;
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 4; c++) {
cout << m3[r][c] << " ";
}
cout << endl;
}
cout << endl << endl;

//print matrix 4
cout << "Matrix 4: " << endl;
for (int r = 0; r < 4; r++) {
for (int c = 0; c < 4; c++) {
cout << m4[r][c] << " ";
}
cout << endl;
}
cout << endl << endl;

cout << endl << endl;
system("pause");
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com