Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lab4
  8. {
  9. class Program
  10. {
  11.  
  12. static void Main(string[] args)
  13. //// Написать программу для определения количества положительных элементов, заданного массива А, состоящего из 20-ти элементов.
  14. //{
  15. // int[] A = new int[20];
  16. // int dsa = 0;
  17.  
  18. // Console.WriteLine("Введите элементы");
  19. // for (int i = 0; i < 20; i++)
  20. // A[i] = int.Parse(Console.ReadLine());
  21. // for (int a = 0; a < 20; a++)
  22. // if (A[a] > 0)
  23. // dsa++;
  24. // Console.ReadKey(true);
  25. // Console.WriteLine("Количество положительных элементов одномерного массива - {0}", dsa);
  26. // Console.Read();
  27. //}
  28.  
  29.  
  30.  
  31.  
  32. //Задан массив А. Поместить положительные элементы этого массива в массив В,А отрицательные в массив С.
  33. //{
  34. // int n = 20;
  35. // int[] array = new int[n];
  36. // Random rand = new Random();
  37. // List<int> B = new List<int>();
  38. // List<int> C = new List<int>();
  39. // for (int i = 0; i < n; i++)
  40. // {
  41. // array[i] = rand.Next(-10, 10);
  42. // Console.Write(array[i] + " ");
  43. // if (array[i] > 0)
  44. // {
  45. // B.Add(array[i]);
  46. // }
  47. // else
  48. // {
  49. // C.Add(array[i]);
  50. // }
  51.  
  52. // }
  53. // Console.WriteLine();
  54. // Console.WriteLine(String.Join(" ", B));
  55. // Console.WriteLine(String.Join(" ", C));
  56. // Console.ReadKey();
  57. //}
  58.  
  59.  
  60. ////Написать процедуру для вывода на печать отрицательных элементов, лежащих на главной диагонали заданного массива A(4,4).
  61. {
  62. int[,] arr = new int[4, 4];
  63. int otricznach = 0;
  64. Console.WriteLine("Введите элементы:");
  65. for (int i = 0; i <= arr.GetLength(0) - 1; i++)
  66. for (int j = 0; j <= arr.GetLength(1) - 1; j++)
  67. arr[i, j] = int.Parse(Console.ReadLine());
  68. Console.WriteLine("\n______________________________\n");
  69. for (int a = 0; a <= arr.GetLength(0) - 1; a++)
  70. {
  71. for (int b = 0; b <= arr.GetLength(1) - 1; b++)
  72. Console.Write($"{arr[a, b]}\t");
  73. Console.WriteLine();
  74. }
  75. Console.WriteLine("\n______________________________\n");
  76. for (int c = 0; c <= arr.GetLength(0) - 1; c++)
  77. {
  78. for (int d = 0; d <= arr.GetLength(1) - 1; d++)
  79. {
  80. if ((d == c) && (arr[c, d] < 0))
  81. {
  82. otricznach++;
  83. Console.Write($"{arr[c, d]}\t");
  84. }
  85. }
  86. }
  87. Console.WriteLine("\n\n{0} Отрицательные", otricznach);
  88. Console.ReadKey(true);
  89. }
  90.  
  91.  
  92.  
  93.  
  94. //Задан массив размером 16. Сформировать из него массив размером 4х4 по строкам.
  95. //{
  96. // string input = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16";
  97. // string[] str = input.Split(' ');
  98. // int count = 0, p = 0; ;
  99.  
  100. // int[,] mas = new int[4, 4];
  101.  
  102. // for (int i = 0; i <= mas.GetLength(0) - 1; i++)
  103. // {
  104. // for (int j = 0; j <= mas.GetLength(1) - 1; j++)
  105. // {
  106. // if (count < 4) { mas[i, j] = int.Parse(str[p]); count++; p++; }
  107. // else break;
  108. // }
  109. // count = 0;
  110. // Console.WriteLine("{0} {1} {2} {3}", mas[i, 0], mas[i, 1], mas[i, 2], mas[i, 3]);
  111.  
  112. // }Console.Read();
  113. //}
  114.  
  115.  
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement