Advertisement
WadeRollins2710

2-Dimensional Array

Mar 14th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _2DimensionalArray
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[,] A = new int[100,100];
  10.             int i, j;
  11.             int n, m;
  12.             Console.Write("Input the number of the row: ");
  13.             n = int.Parse(Console.ReadLine());
  14.             Console.Write("Input the number of the column: ");
  15.             m = int.Parse(Console.ReadLine());
  16.             for (i = 1; i <= n; i++)
  17.                 for (j = 1; j <= m; j++)
  18.                 {
  19.                     Console.Write("A[{0},{0}]: = ", i, j);
  20.                     A[i, j] = int.Parse(Console.ReadLine());
  21.                 }
  22.             for (i = 1; i <= n; i++)
  23.             {
  24.                 for (j = 1; j <= m; j++)
  25.                     Console.Write("{0} ", A[i, j]);
  26.                 Console.WriteLine();
  27.             }
  28.             Console.ReadLine();
  29.             int S = 0, S2 = 0;
  30.             for (i = 1; i <= n; i++)
  31.             {
  32.                 S = S + A[i, i];
  33.                 S2 = S2 + A[i, n - i + 1];
  34.             }
  35.             Console.WriteLine("Sum of the first diagram: {0}", S);
  36.             Console.Write("Sum of the second diagram: {0}", S2);
  37.             Console.ReadLine();
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement