Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace MatrixSum
- {
- using System;
- using System.Numerics;
- public class Program
- {
- public static void Main(string[] args)
- {
- var rows = int.Parse(Console.ReadLine());
- var matrix = GetMatrix(rows);
- BigInteger sum = 0;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- if (col > row)
- {
- sum += matrix[row, col];
- }
- }
- }
- Console.WriteLine(sum);
- }
- static int[,] GetMatrix(int size)
- {
- var matrix = new int[size, size];
- var currentRow = 1;
- var counter = 1;
- for (int row = 0; row < size; row++)
- {
- for (int col = 0; col < size; col++)
- {
- matrix[row, col] = counter;
- counter *= 2;
- if (col == size - 1)
- {
- currentRow *= 2;
- counter = currentRow;
- }
- }
- }
- return matrix;
- }
- /* static void PrintMatrix(int rows, int[,] matrix)
- {
- for (int row = 0; row < rows; row++)
- {
- for (int col = 0; col < rows; col++)
- {
- Console.Write(matrix[row, col] + " ");
- }
- Console.WriteLine();
- }
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement