Venciity

[Jumpstart C#] Multidimensional-Arrays 04

Mar 5th, 2014
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. /*Матрицата A(M,N) е пре­хвър­лена в масива B(K) по ре­до­ве.
  2.  *При зададено i, да се оп­ре­делят индексите на елемента Bi в мат­рицата A.    */
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace _02_NegaitveElements
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.WriteLine("Enter i= ");
  17.             int i = Int32.Parse(Console.ReadLine());
  18.  
  19.             int[,] a = new int[3, 5]
  20.             {
  21.                 {0, 1, 2, 3, 4},
  22.                 {5, 6, 7, 8, 9},
  23.                 {10, 11, 12, 13, 14}
  24.             };
  25.  
  26.             int rows = a.GetLength(0);
  27.             int cols = a.GetLength(1);
  28.  
  29.             int[] b = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
  30.  
  31.             int row = i / cols;
  32.             int col = i % cols;
  33.  
  34.             // int k = row * cols + col;  обратното
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment