class SumDiagonal
{
                public static void main(String args[])
                {
                                int n[][]={{1,2,3},{4,5,6},{7,8,9}};
                                int i,j=3,s=0;
                                for(i=0;i<3;i+)
                                {
                                                j--;
                                                s+=n[i][i]+n[i][j];
                                }
                                System.out.println("Sum Diagonal = "+s);
                }
}

JAVA 27

Advertisements