Isc Computer Project #5
Isc Computer Project #5
Question: Write a program to accept a square matrix and print both the diagonals of it.
Algorithm:
Step 1: START
Step 2: Input n from user
Step 3: Create a double dimension array matrix with order n
Step 4: Set a loop for i=0 till i<n, i increased by 1 each iteration
Sub-Steps:
4.1: Print “Enter n elements in row no. ” + i
4.2: Set an inner loop for j=0 till j<n, j increased by 1 each
iteration
4.3: Input each element from user
Sub-Steps:
5.1: Set a loop for i=0 till i<n, i increased by 1 each
iteration
5.2: Set an inner loop for j=0 till j<n, j increased by 1 each
iteration
5.3: Print each element in order with value of i as row and value of j as column
followed by a blank space
5.4: Print a blank line
Sub-Steps:
6.1: Set a loop for i=0 till i<n, i increased by 1 each
iteration
6.2: Set an inner loop for j=0 till j<n, j increased by 1 each
iteration
6.3: If i=j || (i+j)=n-1, print the element with value of i as
row and value of j as column, followed by tab,
else print only “\t”
6.4: Print a blank line in outer loop
Step 7: END
Source code:
import java.util.Scanner;
class Diagonal
{
System.out.println("\nDiagonals:-");
} //end of main
} //end of class
Variable Description: