plz help me to understand this program

write comments for each line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int main()
{
    int sumDigonal[3][3];
    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++)
        {
            sumDigonal[i][j] = (i + 1) * (j + 1);
        }
    }
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cout << sumDigonal[i][j] <<" ";
        }
        cout << endl;
    }
    for(int i = 0;i < 3;i++)
    {
        int sum = 0;
         
            sum += sumDigonal[i][i];
        cout << sum  << endl;
    }
getch();
}
closed account (2b5z8vqX)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>

using namespace std;

int main() {
        int sumDigonal[3][3]; // Declaration of multi-dimensional array.
        for (int i = 0; // Definition of variable.
         i < 3; // Continue iterating while previously defined variable is less than 3.
         i++) { // Perform post increment operation on i.
                for (int j = 0;
                   j < 3; // Continue iterating until condition evaluates to false.
                   j++) { // Perform post increment operation on j.
                        sumDigonal[i][j] = (i + 1) * (j + 1); 
                        // Assign element at index i, j to the result of the right 
                        // operand of the assignment operator.
                }
        }
        for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                        cout << sumDigonal[i][j] << " "; 
                        // Write arguments to stream by invoking std::basic_ostream<>::operator<<().
                        // http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt
                }
                cout << endl; 
                // Invoke std::endl with std::cout. Write newline character then flush stream.
                // http://en.cppreference.com/w/cpp/io/manip/endl
        }
        for(int i = 0; i < 3; i++) {
                int sum = 0;
                sum += sumDigonal[i][i];
                // Assign sum to sum plus the element at sumDigonal[i][i].
                cout << sum << endl;
                // Invoke std::basic_ostream<>::operator<<() member function on each argument.
        }
}

It didn't feel it was necessary for your understanding of the code to comment every single line. I'll go into more detail if you still don't understand the code after reading my comments.
Topic archived. No new replies allowed.