Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5. class Program
  6. {
  7.  
  8. static void Main(string[] args)
  9. {
  10.  
  11. /* Ситуативно, для чтения
  12. * foreach (int i in nums)
  13. {
  14. Console.WriteLine(i);
  15. }
  16. int[,] mas = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
  17.  
  18. int rows = mas.GetUpperBound(0) + 1;
  19. int columns = mas.Length / rows;
  20. // или так
  21. // int columns = mas.GetUpperBound(1) + 1;
  22.  
  23. for (int i = 0; i < rows; i++)
  24. {
  25. for (int j = 0; j < columns; j++)
  26. {
  27.  
  28. Console.Write(mas[i, j]);
  29. Console.Write("\t");
  30. }
  31. Console.WriteLine();
  32. }*/
  33.  
  34.  
  35.  
  36.  
  37.  
  38. /* Задан массив действительных чисел размерности 10х10.Найти суммы элементов каждой строки, произведения элементов каждого столбца,
  39. * и максимальный элемент главной диагонали.*/
  40. var rnd = new Random();
  41. int[,] arr = new int[10, 10];
  42. int sum ;
  43. for (int i = 0; i < 10; i++)
  44. {
  45. for (int j = 0; j < 10; j++)
  46. {
  47. arr[i, j] = rnd.Next(1, 9);
  48. Console.Write(arr[i, j]);
  49. Console.Write("\t");
  50. }
  51. Console.WriteLine();
  52. }
  53. for (int i = 0; i < 10; i++)
  54. {
  55. sum = 0;
  56. for (int j = 0; j < 10; j++)
  57. {
  58. sum += arr[i, j];
  59.  
  60. }
  61. Console.WriteLine(" sum= " + sum);
  62. }
  63. int comp=1;
  64. for (int i = 0; i < 10; i++)
  65. {
  66. comp = 1;
  67. for (int j = 0; j < 10; j++)
  68. {
  69. comp*= arr[j, i];
  70. }
  71. Console.WriteLine(" composition= " + comp);
  72. }
  73. int a = 0;
  74. int b = 0;
  75. int max=0;
  76. for ( a = 0 , b=0; a < 9 && b<9; a++,b++)
  77. {
  78. if (arr[a,b] >arr [a+1,b+1] )
  79. {
  80. max = arr[a, b];
  81. arr[a, b] = arr[a + 1, b + 1];
  82. arr[a + 1, b + 1] = max;
  83.  
  84. }
  85. }
  86. Console.WriteLine("maximum= "+arr[9,9]);
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement