gpt4 book ai didi

c++ - C/C++ 无法在 for 循环中运行 for 循环

转载 作者:行者123 更新时间:2023-11-30 20:17:14 25 4
gpt4 key购买 nike

这是我的代码:

#include <stdio.h>
/*
CALCULATING INVERSE OF A MATRIX
*/
int main(){

int matris[3][3];
int i = 0;
int j = 0;
for(i; i<3;i++){

for(j;j<3;j++){

scanf("%d", &matris[i][j]);
}
printf("%d", matris[i][j]);
}
}

我知道它的基本原理,但我遇到了麻烦,我的编译器是 Dev-C++,顺便说一句,我的操作系统是 Windows 10,当我运行此代码并按 1,2,3 时,这是我唯一的输出可以看到。

1
2
3
0430
--------------------------------
Process exited after 2.351 seconds with return value 1

我不知道我的错误在哪里,谢谢帮助

编辑

我将代码编辑为:

int main(){

int matris[3][3];
int i,j;
for(i = 0; i<3; i++){
for (j=0;j<3;j++){
scanf("%d", &matris);
}
}

for(i = 0; i<3; i++){

for (j=0;j<3;j++){

printf("%d ", matris);
}
}

}

但我仍然看不到正确的输出。

输出:

1
2
3
4
5
6
7
8
9
6487536 6487536 6487536 6487536 6487536 6487536 6487536 6487536 6487536

但是,当然预期的输出类似于 3x3 矩阵和整数 1 到 9

最佳答案

可以,但是在进入 i 的每个值的循环之前,您需要将 j 设置为初始值现在它只执行一次 j 循环,下次执行时它会发现 j > 然后 3,所以它会跳过它

关于c++ - C/C++ 无法在 for 循环中运行 for 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58363849/

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