Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace arraysExample
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Declare and initialize the matrix
- int[,] matrix =
- {
- {2,3,5,49,2},
- {5,2,1,4,5},
- {17,2,3,4,5},
- {4,8,9,6,3}
- };
- //find the maximum sum platform of size 2x2
- int bestSum = int.MinValue;
- int bestRow = 0;
- int bestCol = 0;
- for(int row = 0;row < matrix.GetLength(0)-1; row++)
- {
- for(int col = 0; col< matrix.GetLength(1)-1; col++)
- {
- int sum = matrix[row, col] + matrix[row, col + 1] + matrix[row + 1, col] + matrix[row + 1, col + 1];
- if(sum > bestSum)
- {
- bestSum = sum;
- bestRow = row;
- bestCol = col;
- }
- }
- }
- //print the result
- Console.WriteLine("The best platform is: ");
- Console.WriteLine(" {0} {1}", matrix[bestRow,bestCol], matrix[bestRow,bestCol+1]);
- Console.WriteLine(" {0} {1}", matrix[bestRow+1,bestCol], matrix[bestRow+1,bestCol+1]);
- Console.WriteLine("The maximum sum is : {0}", bestSum);
- Console.ReadLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment