0% found this document useful (0 votes)
4 views3 pages

Q17'

The document outlines an algorithm for modifying the diagonals of a square matrix. It includes steps for user input of the matrix size and replacement number, as well as the process for replacing diagonal elements with the specified number. Finally, it instructs to print both the original and modified matrices.

Uploaded by

itsmans74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Q17'

The document outlines an algorithm for modifying the diagonals of a square matrix. It includes steps for user input of the matrix size and replacement number, as well as the process for replacing diagonal elements with the specified number. Finally, it instructs to print both the original and modified matrices.

Uploaded by

itsmans74
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Output :

Algorithm: Modify Matrix Diagonals

1. Start

2. Input:
o Get the size of the matrix (n) from the user.
o Get the replacement number (x) from the user.
3. Initialization:
o Create a 2D integer array a of size n x n to store the matrix elements.
4. Input Matrix Elements:
o For each row i from 0 to n-1:
 For each column j from 0 to n-1:
 Get the element a[i][j] from the user.
5. Modify Diagonals:
o For each row i from 0 to n-1:
 For each column j from 0 to n-1:
 If i == j (primary diagonal) or i + j == n - 1 (secondary diagonal):
 Replace a[i][j] with x.
6. Output:
o Print the original matrix a.
o Print the modified matrix a (with diagonals replaced).
7. End

You might also like