product of numbers of an array

hi, the guestion says "find the product of the numbers which are placed above the main diagonal and below the secondary diagonal AT THE SAME TIME." (i think it's (arr[1][3]) * (arr[2][3]) i my case, right?)

i'm confused as to how you correctly intup the array from the keyboard; and also if thats the right way to write this code

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
#include <iostream>
using namespace std;

int main()
{
    setlocale(LC_ALL, "Russian");

    const int ROW = 4;
    const int COL = 4;

    int arr[ROW][COL];

    for (int i = 0; i < ROW; i++)
    {
        for (int j = 0; i < COL; j++)
        {
            cout << "Введите матрицу 4х4: " << endl; // enter matrix 4x4
            cin >> arr[i][j];
        }
    }

     int product = ( (arr[1][3])  * (arr[2][3]) );

    for (int i = 0; i < ROW; i++)
    {
        for (int j = 0; i < COL; j++)
        {
            cout << "Произведение главной и побочной диагонали = " << product << endl; // the product =

        }
    }
    
    return 0;
} 
Last edited on
What do you think this does?
 
    setlocale(LC_ALL, "Russian");
sure, you can input this way. I would print which location you are on each time on line 17, eg
4x4: row: "<< i <<"column: "<< j << endl; (whatever that is in your language)

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

the main diagonal is 0505
the one above that is 161

I am not sure what a 'side diagonal' is? Are you talking about the ones going up instead of down (I know them as 'secondary') ?
it would be 307 for example of one, but I do not know which.
so you have 2 ways to understand the question from here..

one loop that does both diagonals at once (which is silly because you can hard-code both, but whatever, you can iterate it)
or two threads that do them in parallel "at the same time".

so you need something like
product1 = product2 = 1;
for all the rows
product1 *= matrix[row][?]
product2 *= matrix[row][#]

where you need to figure out the correct indices to multiply based off what is asked.
note that not all rows will have a term; for example the diagonal above the primary only has 3 terms, not 4, so one of the row iterations should do nothing, use a condition to control this.
Last edited on
@jonnin thank you lots! sorry, the 'side diagonal' is 3692 from your matrix. so if i were to multiply the numbers that are above the main and below the 'side'(guessing it's called secondary) diagonals at the same time, then it'be 7*1
@dutch it lets me use russian letters, otherwise i'd just get "??????" or something like that lol
I don't know where you got 7*1. But I think you see what to do... locate the cells you need to multiply together in a loop and do so...

secondary diagonals go Up instead of Down, eg 2963 etc, from left to right. you gave right to left, going down. I have no idea what the official name of that is (if not "side"), or what it might be good for (apart from computing determinants the hard way). Ill have to review that... things I don't use fade quickly these days.
Last edited on
It lets me use Russian letters

You can set this system-wide if you want, for example by editing /etc/environment
@mbozzi thanks for the tip:)
@jonnin thank you a lot, much appreciated :)
Topic archived. No new replies allowed.