Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
错误的原因是什么? 我是C++新手。这是我的两个3x3矩阵求和的程序,我不知道如何退出while循环,似乎我只能退出for循环。 请帮忙。 这是我的密码 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <windows.h> int main() { double a[3][3]; double b[3][3]; char str[40]; int step = 1; double resultan; while (1) { for(int i=1; i<=3; i++) { for(int j=1; j<=3; j++) { if (step==1) { printf("Enter value of matrix a row %d column %d = ", i, j); scanf("%lf", &a[i][j]); } if (step==2) { printf("Enter value of matrix b row %d column %d = ", i, j); scanf("%lf", &b[i][j]); } if (step==3) { resultan = a[i][j] + b[i][j]; printf("Matriks a[%d][%d] + Matriks b[%d][%d] = ", i,j,i,j); printf("%lf + %lf = %lf\n", a[i][j],b[i][j],resultan); } if (i==3 && j==3) { step++; Sleep(1); } } } if (step==4) { break; } } } #包括 #包括 #包括 #包括 int main(){ 双a[3][3]; 双b[3][3]; char-str[40]; int步长=1; 双结果素; 而(1){ 对于(inti=1;i_C++_C - Fatal编程技术网

错误的原因是什么? 我是C++新手。这是我的两个3x3矩阵求和的程序,我不知道如何退出while循环,似乎我只能退出for循环。 请帮忙。 这是我的密码 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <windows.h> int main() { double a[3][3]; double b[3][3]; char str[40]; int step = 1; double resultan; while (1) { for(int i=1; i<=3; i++) { for(int j=1; j<=3; j++) { if (step==1) { printf("Enter value of matrix a row %d column %d = ", i, j); scanf("%lf", &a[i][j]); } if (step==2) { printf("Enter value of matrix b row %d column %d = ", i, j); scanf("%lf", &b[i][j]); } if (step==3) { resultan = a[i][j] + b[i][j]; printf("Matriks a[%d][%d] + Matriks b[%d][%d] = ", i,j,i,j); printf("%lf + %lf = %lf\n", a[i][j],b[i][j],resultan); } if (i==3 && j==3) { step++; Sleep(1); } } } if (step==4) { break; } } } #包括 #包括 #包括 #包括 int main(){ 双a[3][3]; 双b[3][3]; char-str[40]; int步长=1; 双结果素; 而(1){ 对于(inti=1;i

错误的原因是什么? 我是C++新手。这是我的两个3x3矩阵求和的程序,我不知道如何退出while循环,似乎我只能退出for循环。 请帮忙。 这是我的密码 #include <stdio.h> #include <string.h> #include <stdlib.h> #include <windows.h> int main() { double a[3][3]; double b[3][3]; char str[40]; int step = 1; double resultan; while (1) { for(int i=1; i<=3; i++) { for(int j=1; j<=3; j++) { if (step==1) { printf("Enter value of matrix a row %d column %d = ", i, j); scanf("%lf", &a[i][j]); } if (step==2) { printf("Enter value of matrix b row %d column %d = ", i, j); scanf("%lf", &b[i][j]); } if (step==3) { resultan = a[i][j] + b[i][j]; printf("Matriks a[%d][%d] + Matriks b[%d][%d] = ", i,j,i,j); printf("%lf + %lf = %lf\n", a[i][j],b[i][j],resultan); } if (i==3 && j==3) { step++; Sleep(1); } } } if (step==4) { break; } } } #包括 #包括 #包括 #包括 int main(){ 双a[3][3]; 双b[3][3]; char-str[40]; int步长=1; 双结果素; 而(1){ 对于(inti=1;i,c++,c,C++,C,而言,问题在于数组中的索引从0到N-1,所以只需更改 for (int i = 1 ; i <= 3 ; i++) 使用 while(步骤

而言,问题在于数组中的索引从
0
N-1
,所以只需更改

for (int i = 1 ; i <= 3 ; i++)
使用

while(步骤<4)
如果你的代码非常复杂,那么写一个函数
fill\u array()
,然后把你要填充的数组及其大小传递给它。这样你就不需要这么复杂的逻辑了


循环体做了太多的事情,如果您希望代码健壮且可维护,它应该只做一件事。

这不是,您知道和之间的区别吗?当您说“错误”时,这是什么意思?生成错误?运行时错误或崩溃?意外结果?请编辑您的问题以包含更多详细信息。它的运行时错误,当变量step=4时崩溃。非常感谢,我刚刚将a和b数组的大小更改为4x4,现在我可以退出while循环。
for (int i = 0 ; i < 3 ; ++i)
while (1)
while (step < 4)