Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Task1010
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.         }
  13.         static void PrintArray(int[,] arr)
  14.         {
  15.             for (int i = 0; i < arr.GetLength(0); i++)
  16.             {
  17.                 for (int j = 0; j < arr.GetLength(1); j++)
  18.                 {
  19.                     Console.Write(arr[i,j] + ",");
  20.                 }
  21.                 Console.WriteLine();
  22.             }
  23.         }
  24.         static int[,] CreateArray()
  25.         {
  26.             int[,] arr = new int[15, 20];
  27.             for (int i = 0; i < arr.GetLength(0); i++)
  28.             {
  29.                 for (int j = 0; j < arr.GetLength(1); j++)
  30.                 {
  31.                     arr[i, j] = i;
  32.                 }
  33.             }
  34.             return arr;
  35.         }
  36.         static int[,] Kefel()
  37.         {
  38.             int[,] arr = new int[10, 10];
  39.             for (int i = 0; i < arr.GetLength(0); i++)
  40.             {
  41.                 for (int j = 0; j < arr.GetLength(1); j++)
  42.                 {
  43.                     arr[i, j] = (i + 1) * (j + 1);
  44.                 }
  45.             }
  46.             return arr;
  47.         }
  48.         static int[,] CreateRandom(int r, int c)
  49.         {
  50.             Random rand = new Random();
  51.             int[,] arr = new int[r, c];
  52.             for (int i = 0; i < arr.GetLength(0); i++)
  53.             {
  54.                 for (int j = 0; j < arr.GetLength(1); j++)
  55.                 {
  56.                     arr[i, j] = rand.Next(0,10);
  57.                 }
  58.             }
  59.             return arr;
  60.         }
  61.         static void FindMax(int[,] arr)
  62.         {
  63.             int max = 0;
  64.             string maxim = "";
  65.             for (int i = 0; i < arr.GetLength(0); i++)
  66.             {
  67.                 for (int j = 0; j < arr.GetLength(1); j++)
  68.                 {
  69.                     if (arr[i, j] > max)
  70.                     {
  71.                         max = arr[i, j];                      
  72.                     }
  73.                 }
  74.             }
  75.             for (int i = 0; i < arr.GetLength(0); i++)
  76.             {
  77.                 for (int j = 0; j < arr.GetLength(1); j++)
  78.                 {
  79.                     if (arr[i, j] == max)
  80.                     {
  81.                         maxim += i.ToString() + "," + j.ToString() + " ";
  82.                     }
  83.                 }
  84.             }
  85.             Console.WriteLine("The max number was: " + max);
  86.             Console.WriteLine("It appeared in: " + maxim);
  87.         }
  88.         static void Diagnol(int[,] arr)
  89.         {
  90.             if (arr.GetLength(0) != 6 || arr.GetLength(1) != 6)
  91.             {
  92.                 Console.WriteLine("There was a problem with the array that was put in");
  93.                 return;
  94.             }
  95.             PrintArray(arr);
  96.             Console.WriteLine();
  97.             for (int i = 0; i < arr.GetLength(0); i++)
  98.             {
  99.                 for (int j = 0; j < arr.GetLength(1); j++)
  100.                 {
  101.                     if (i == j)
  102.                         arr[i, j] = 1;
  103.                     if (j < i)
  104.                         arr[i, j] = 0;
  105.                 }
  106.             }
  107.         }
  108.         static void Inner(int[,] arr)
  109.         {
  110.             int[,] arr2 = new int[5, 5];
  111.             if(arr.GetLength(0) != 7 || arr.GetLength(1) != 7)
  112.             {
  113.                 Console.WriteLine("There was a problem with the array");
  114.                 return;
  115.             }
  116.             PrintArray(arr);
  117.             Console.WriteLine();
  118.             for (int i = 0; i < arr2.GetLength(0); i++)
  119.             {
  120.                 for (int j = 0; j < arr2.GetLength(1); j++)
  121.                 {
  122.                     arr2[i, j] = arr[i, j];
  123.                 }
  124.             }
  125.             PrintArray(arr2);
  126.         }
  127.         static bool IsPositive()
  128.         {
  129.            
  130.             int summain = 0;
  131.             int sumsec = 0;
  132.             int[,] arr = CreateRandom(7, 7);
  133.             PrintArray(arr);
  134.             Console.WriteLine();
  135.             for (int i = 0; i < arr.GetLength(0); i++)
  136.             {
  137.                 summain += arr[i, i];
  138.             }
  139.             for (int i = 0; i < arr.GetLength(0); i++)
  140.             {
  141.                 sumsec += arr[i, arr.GetLength(0) - 1 - i];
  142.             }
  143.             if (summain > sumsec)
  144.                 return true;                          
  145.             return false;
  146.         }
  147.         static bool IsMagic(int n,int[,] arr)
  148.         {
  149.             int sumAlahson1=0;
  150.             int sumAlahson2=0;
  151.             for(int i=0;i<n;i++){
  152.                 sumAlahson1+=arr[i,i];
  153.                 sumAlahson2+=arr[arr.Length-i,arr.Length-i];
  154.             }
  155.             if(sumAlahson1!=sumAlahson2)
  156.                 return false;
  157.             for(int i=0;i<n;i++){
  158.                 int sumRow=0,sumColumn=0;
  159.                 for(int j=0;j<n;j++){
  160.                     sumRow+=arr[i,j];
  161.                     sumColumn+=arr[j,i];
  162.                 }
  163.                 if(sumRow!=sumAlahson1||sumColumn!=sumAlahson2)
  164.                     return false;
  165.             }
  166.             return true;
  167.         }
  168.     }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement