Diagonal Difference

  • + 4 comments

    I still have one extra variable, which is unnecessary

    static void Main(String[] args) {
            int n = Convert.ToInt32(Console.ReadLine());
            int[][] a = new int[n][];
            for(int a_i = 0; a_i < n; a_i++){
               string[] a_temp = Console.ReadLine().Split(' ');
               a[a_i] = Array.ConvertAll(a_temp,Int32.Parse);
            }
            
            int totalSum=0;
            int j=n-1;
            for(int i=0;i<n;i++){
                totalSum=a[i][i]-a[j][i]+totalSum;
                j--;
            }
            
            Console.WriteLine(Math.Abs(totalSum));
        }