Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed The parallel to the diagonal in C++

0 votes
asked Feb 5, 2019 by Florentin (190 points)
closed Feb 13, 2019 by Florentin

Give a matrix m with N lines and N columns and two numbers i and j representing the position in the array of the first element of a parallel to the main diagonal. Show all the elements from the top down from that parallel to the diagonal.
        Input data
             From the first line, read the N number on the keypad. The following N lines read N natural numbers representing the coordinates of the matrix. The last line reads the numbers i and j.
       Output data
           The program will display on screen a number of numbers representing the elements on the diagonal parallel.

Restrictions and clarifications

  • 1 <= N <= 50
  • 0 < i ,j <= N
  • 1 <= m[i][j] <= 100

    always i = 1 or j = 1
The lines and columns are numbered 1 to N

#include<iostream>

using namespace std;

int

main ()

{

  int m[51][51], i, j, n, d;

  cout << "n=";

  cin >> n;

  cout << "intoducere elemente matrice= " << endl;

  for (i = 1; i <= n; i++)

    for (j = 1; j <= n; j++)

      {

//cout << "m[" << i << "," << j << "]=";

cin >> m[i][j];

      }

  cout << "i,j=";

  cin >> i >> j;

  if (i < j)

    {

      d = j - 1;

    }

  else

    {

      d = i - 1;

    }

  if (i < j)

    {

      cout << "parcugere matrice deasupra diagonalei principala= " << endl;

      for (i = 1; i < n; i++)

{

  j = i + d;

  if (j <= n)

    {

      cout << m[i][j] << "  ";

    }

}

      cout << endl;

    }

  else

    {

      cout << "parcugere matrice sub diagonala principala= " << endl;

      for (i = 2; i <= n; i++)

{

  j = i - d;

  if (j > 0)

    {

      cout << m[i][j] << "   ";

    }

}

      cout << endl;

    }

  return 0;

}

Anyone please you confirm this algorithm is correct for this problem?

If you have any solution please help me.Thanks.

closed with the note: I'm solved this problem

1 Answer

–2 votes
answered Feb 13, 2019 by auraGB (250 points)
WHAT TF DO U WANT ???????????????????????????????????????

SPEAK ENGLISH
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...