desislava_topuzakova

3. Минимум по колони

Mar 20th, 2021
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Arrays
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int rows = int.Parse(Console.ReadLine());
  12. int cols = int.Parse(Console.ReadLine());
  13.  
  14. int[,] intMatrix = new int[rows, cols];
  15.  
  16. for (int row = 0; row < rows; row++)
  17. { //1 2 3 5
  18. int[] numbersRow = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  19. for (int col = 0; col < cols; col++)
  20. {
  21. intMatrix[row, col] = numbersRow[col];
  22. }
  23. }
  24.  
  25. for (int col = 0; col < cols; col++)
  26. {
  27. int min = int.MaxValue;
  28. for (int row = 0; row < rows; row++)
  29. {
  30. int currentElement = intMatrix[row, col];
  31. if(currentElement < min)
  32. {
  33. min = currentElement;
  34. }
  35. }
  36.  
  37. Console.WriteLine("Min number in column " + col + ": " + min);
  38. }
  39.  
  40.  
  41.  
  42. }
  43.  
  44. static void printMatrix(int [,] intMatrix)
  45. {
  46. for (int row = 0; row < intMatrix.GetLength(0); row++)
  47. {
  48. for (int col = 0; col < intMatrix.GetLength(1); col++)
  49. {
  50. Console.Write(intMatrix[row, col] + " ");
  51. }
  52. Console.WriteLine();
  53. }
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment