Venciity

[Jumpstart C#] Multidimensional-Arrays 01-Product2

Mar 5th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. /* Дадена е матрицата A(M,N). При зададено k, намерете:
  2.     произведението на елементите без тези от k-тия стълб.   */
  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 _01_Product2
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Console.Write("Enter k: ");
  17.             int k = Int32.Parse(Console.ReadLine());
  18.  
  19.             int[,] a = new int[3, 3]
  20.             {
  21.                 {5, 9, 4},
  22.                 {3, 0, 3},
  23.                 {1, 6, 3}
  24.             };
  25.  
  26.             int rows = a.GetLength(0);
  27.             int cols = a.GetLength(1);
  28.  
  29.             long product = 1;
  30.             for (int i = 0; i < cols; i++)
  31.             {
  32.                 if (i != k)
  33.                 {
  34.                     for (int j = 0; j < rows; j++)
  35.                     {
  36.                         product *= a[j, i];
  37.                     }
  38.                 }
  39.             }
  40.             Console.WriteLine("The product is {0}", product);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment