//Program to find the sum of the main and right diagonals of a 2D array
import java.io.*;
public class Diagonals
{
public static void main(String[]args)throws IOException
{
int arr[][]={{1,2,3,4},{1,2,3,4},{1,2,3,4},{1,2,3,4}};
int maindiag=0;int rightdiag=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
if(i==j)
{
maindiag=maindiag+arr[i][j];
}
}
}
System.out.println("The sum of the main diagonal is "+maindiag);
int c=3;
for(int i=0;i<4;i++)
{
rightdiag=rightdiag+arr[i][c];
c--;
}
System.out.println("Sum of the right diag. is "+rightdiag);
}
}
So for this program, how exactly do I write the algorithm?? I mean, what's the standard format?? Thanks in advance :)