abasar

exercises 6/3

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