Advertisement
abasar

Exercises 3/2

Mar 2nd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.88 KB | None | 0 0
  1. //#7
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         public static void PrintMatrix(int[,] a)
  13.         {
  14.             for (int i = 0; i < a.GetLength(0); i++)
  15.             {
  16.                 for (int j = 0; j < a.GetLength(1); j++)
  17.                     Console.Write("{0,-7}", a[i, j]);
  18.                 Console.WriteLine();
  19.             }
  20.         }
  21.         public static void KeletMatrix(int[,] a)
  22.         {
  23.             for (int i = 0; i < a.GetLength(0); i++)
  24.                 for (int j = 0; j < a.GetLength(1); j++)
  25.                     a[i, j] = int.Parse(Console.ReadLine());
  26.         }
  27.         public static void KeletHad(int[] a)
  28.         {
  29.             for (int i = 0; i < a.Length; i++)
  30.                 a[i] = int.Parse(Console.ReadLine());
  31.         }
  32.         public static int SumMatrix(int[,] a)
  33.         {
  34.             int sum = 0;
  35.             for (int i = 0; i < a.GetLength(0); i++)
  36.                 for (int j = 0; j < a.GetLength(1); j++)
  37.                     sum += a[i, j];
  38.             return sum;
  39.         }
  40.         public static int SumRows(int[,] a, int rowNum)
  41.         {
  42.             int shum = 0;
  43.             for (int i = 0; i < a.GetLength(1); i++)
  44.                 shum += a[rowNum, i];
  45.             return shum;
  46.         }
  47.         public static int SumColumns(int[,] a, int columnNum)
  48.         {
  49.             int shum = 0;
  50.             for (int i = 0; i < a.GetLength(0); i++)
  51.                 shum += a[i, columnNum];
  52.             return shum;
  53.         }
  54.         public static int BiggestInRow(int[,] a, int rowNum)
  55.         {
  56.             int max = a[rowNum, 0];
  57.             for (int i = 1; i < a.GetLength(1); i++)
  58.                 if (max < a[rowNum, i])
  59.                     max = a[rowNum, i];
  60.             return max;
  61.         }
  62.         public static bool MagicSquare(int[,] a)
  63.         {
  64.             bool magical = true;
  65.             int shum = SumRows(a, 0);
  66.             int i = 1;
  67.             while (magical && i < a.GetLength(0))
  68.             {
  69.                 magical = shum == SumRows(a, i);
  70.                 i++;
  71.             }
  72.             if (!magical)
  73.                 return magical;
  74.             i = 0;
  75.             while (magical && i < a.GetLength(1))
  76.             {
  77.                 magical = shum == SumColumns(a, i);
  78.                 i++;
  79.             }
  80.             if (!magical)
  81.                 return magical;
  82.             int shumA = 0;
  83.             for (i = 0; i < a.GetLength(0); i++)
  84.                 shumA += a[i, i];
  85.             if (shumA != shum)
  86.                 return false;
  87.             shumA = 0;
  88.             for (i = 0; i < a.GetLength(0); i++)
  89.                 shumA += a[i, a.GetLength(0) - i - 1];
  90.             return shumA == shum;
  91.         }
  92.         static void Main(string[] args)
  93.         {
  94.             int[,] a = new int[40, 4];
  95.             int[] memuzaim = new int[a.GetLength(0)];
  96.             KeletMatrix(a);
  97.             for (int i = 0; i < memuzaim.Length; i++)
  98.                 memuzaim[i] = SumRows(a, i);
  99.             double memuza = 0;
  100.             for (int i = 0; i < memuzaim.Length; i++)
  101.                 memuza += (double)memuzaim[i];
  102.             memuza /= a.GetLength(0);
  103.             Console.WriteLine(memuza);
  104.             for (int i = 0; i < a.GetLength(1); i++)
  105.             {
  106.                 Console.WriteLine(i);
  107.                 double memuza0 = 0;
  108.                 for (int j = 0; j < a.GetLength(0); j++)
  109.                     memuza0 += (double)a[j, i];
  110.                 memuza0 /= a.GetLength(0);
  111.                 Console.WriteLine(memuza0);
  112.             }
  113.             for (int i = 0; i < memuzaim.Length; i++)
  114.                 Console.WriteLine((double)memuzaim[i]-memuza);
  115.         }
  116.     }
  117. }
  118.  
  119. //#10
  120. using System;
  121. using System.Collections.Generic;
  122. using System.Linq;
  123. using System.Text;
  124. using System.Threading.Tasks;
  125.  
  126. namespace ConsoleApplication1
  127. {
  128.     class Program
  129.     {
  130.         public static void PrintMatrix(int[,] a)
  131.         {
  132.             for (int i = 0; i < a.GetLength(0); i++)
  133.             {
  134.                 for (int j = 0; j < a.GetLength(1); j++)
  135.                     Console.Write("{0,-7}", a[i, j]);
  136.                 Console.WriteLine();
  137.             }
  138.         }
  139.         public static void KeletMatrix(int[,] a)
  140.         {
  141.             for (int i = 0; i < a.GetLength(0); i++)
  142.                 for (int j = 0; j < a.GetLength(1); j++)
  143.                     a[i, j] = int.Parse(Console.ReadLine());
  144.         }
  145.         public static void KeletHad(int[] a)
  146.         {
  147.             for (int i = 0; i < a.Length; i++)
  148.                 a[i] = int.Parse(Console.ReadLine());
  149.         }
  150.         public static int SumMatrix(int[,] a)
  151.         {
  152.             int sum = 0;
  153.             for (int i = 0; i < a.GetLength(0); i++)
  154.                 for (int j = 0; j < a.GetLength(1); j++)
  155.                     sum += a[i, j];
  156.             return sum;
  157.         }
  158.         public static int SumRows(int[,] a, int rowNum)
  159.         {
  160.             int shum = 0;
  161.             for (int i = 0; i < a.GetLength(1); i++)
  162.                 shum += a[rowNum, i];
  163.             return shum;
  164.         }
  165.         public static int SumColumns(int[,] a, int columnNum)
  166.         {
  167.             int shum = 0;
  168.             for (int i = 0; i < a.GetLength(0); i++)
  169.                 shum += a[i, columnNum];
  170.             return shum;
  171.         }
  172.         public static int BiggestInRow(int[,] a, int rowNum)
  173.         {
  174.             int max = a[rowNum, 0];
  175.             for (int i = 1; i < a.GetLength(1); i++)
  176.                 if (max < a[rowNum, i])
  177.                     max = a[rowNum, i];
  178.             return max;
  179.         }
  180.         public static bool MagicSquare(int[,] a)
  181.         {
  182.             bool magical = true;
  183.             int shum = SumRows(a, 0);
  184.             int i = 1;
  185.             while (magical && i < a.GetLength(0))
  186.             {
  187.                 magical = shum == SumRows(a, i);
  188.                 i++;
  189.             }
  190.             if (!magical)
  191.                 return magical;
  192.             i = 0;
  193.             while (magical && i < a.GetLength(1))
  194.             {
  195.                 magical = shum == SumColumns(a, i);
  196.                 i++;
  197.             }
  198.             if (!magical)
  199.                 return magical;
  200.             int shumA = 0;
  201.             for (i = 0; i < a.GetLength(0); i++)
  202.                 shumA += a[i, i];
  203.             if (shumA != shum)
  204.                 return false;
  205.             shumA = 0;
  206.             for (i = 0; i < a.GetLength(0); i++)
  207.                 shumA += a[i, a.GetLength(0) - i - 1];
  208.             return shumA == shum;
  209.         }
  210.         static void Main(string[] args)
  211.         {
  212.             int[,] a = new int[30,30];
  213.             KeletMatrix(a);
  214.             for (int i = 0; i < a.GetLength(0); i++)
  215.                 for (int j = 0; j < a.GetLength(1); j++)
  216.                     if (a[i, j] >  )
  217.         }
  218.     }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement