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;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Insert(int[,] arr)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- Console.Write(i + " " + j + ": ");
- arr[i, j] = int.Parse(Console.ReadLine());
- }
- }
- }
- static bool Check(int[,] arr)
- {
- bool ok = true;
- int length = 0;
- int tempcount = 0;
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- length += arr[0, j];
- }
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- tempcount += arr[i, j];
- }
- if (tempcount != length)
- ok = false;
- tempcount = 0;
- }
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- tempcount += arr[i, j];
- }
- if (tempcount != length)
- ok = false;
- tempcount = 0;
- }
- /////////////
- int var = 0;
- for (int j = 0; j < arr.GetLength(0); j++)
- {
- tempcount += arr[var, j];
- var++;
- }
- if (tempcount != length)
- ok = false;
- tempcount = 0;
- var = arr.GetLength(1)-1;
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- tempcount += arr[i, var];
- var--;
- }
- if (tempcount != length)
- ok = false;
- tempcount = 0;
- return ok;
- }
- static void Main(string[] args)
- {
- int a = int.Parse(Console.ReadLine());
- int[,] square = new int[a, a];
- Insert(square);
- Console.Clear();
- bool check = Check(square);
- Console.WriteLine(check);
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment