Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.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++ 如何使用for循环将元素加载到每个数组中,然后将每个数组的和输出到一个和数组中?_C++_Arrays - Fatal编程技术网

C++ 如何使用for循环将元素加载到每个数组中,然后将每个数组的和输出到一个和数组中?

C++ 如何使用for循环将元素加载到每个数组中,然后将每个数组的和输出到一个和数组中?,c++,arrays,C++,Arrays,各位好, 我正在研究一个C++应用程序,它将把元素加载到10行10列的第一个数组中,并将元素加载到第二个数组中,该数组也是10个10,然后将每个数组元素添加到一起,并将它们放在一个称为“和”的数组中。例如,在实际中,当你做矩阵加法时,你会做下面这样的事情,但是我的数组比这个复杂。问题是如何使用嵌套for循环将元素加载到每个数组中。任何例子都将不胜感激!!!这是我到目前为止的代码。我知道如何在数组中输出元素,但我从未使用for循环将元素加载到数组中 [1 2 4]+[2 3 7]=[3 5 11]

各位好,

我正在研究一个C++应用程序,它将把元素加载到10行10列的第一个数组中,并将元素加载到第二个数组中,该数组也是10个10,然后将每个数组元素添加到一起,并将它们放在一个称为“和”的数组中。例如,在实际中,当你做矩阵加法时,你会做下面这样的事情,但是我的数组比这个复杂。问题是如何使用嵌套for循环将元素加载到每个数组中。任何例子都将不胜感激!!!这是我到目前为止的代码。我知道如何在数组中输出元素,但我从未使用for循环将元素加载到数组中


[1 2 4]+[2 3 7]=[3 5 11]

您自己有没有尝试过解决这个问题?你的代码没有显示任何形式的for循环或你意图的任何其他部分@UnholySheep你认为你可以向我推荐一些关于此类问题的在线资源吗?@UnholySheep有任何关于如何解决我的问题的参考吗?@Shibli-你能帮我吗?我真的需要一些帮助。@Shibli-那么您所做的是创建一个for循环,遍历第一个矩阵的所有行和列,然后将每个元素存储到第一个矩阵中?实际值在哪里起作用?我知道每个矩阵将有100个元素,然后总和也将有100个元素。代码要求矩阵的每个元素都有一个值,并存储您用std::cin给出的任何值。你说的实际值是什么意思?
#include "stdafx.h" 
#include <iostream> 
#include <cstdlib>
#include <string> 

using namespace std;   

int main() 
{      
    /*      
    For this version, the matrices are square (defined by size, which is a maximum of 10).
    Thus, m & n (rows & columns) are the same.
    Later versions can allow the number of rows and columns to be different. 

    size - the dimension of both matrices.  
    m - the number of rows   
    n - the number of columns  
    c - the delimiter of the outer loop         
    d - the delimiter of the inner loop 

    first  - the first matrix  
    second - the second matrix 
    sum - holds the sum of the 2 matrices      
    */ 

    int size, m, n, c, d, first[10][10], second[10][10], sum[10][10]; 

    cout << "Enter the number of rows and columns of matrices: ";         
    cin >> size;  m = size; n = size;    

    // Load the first matrix 
    cout << "Enter the elements of first matrix: "; 

    // Load the second matrix    

    cout << "Enter the elements of second matrix: ";    

    // Sum the elements of the matrices 

    // Print the sum matrix

    cout << "Hit any key to continue" << endl; 

    system ("pause");    return 0; 
} 
for (int i=0; i<size; ++i)
{
    for (int j=0; j<size; ++j)
    {
        std::cout << "first[" << i << "][" << j << "]" << std::endl;
        std::cin >> first[i][j];
    }
}