Advertisement
Guest User

EZ

a guest
Feb 27th, 2020
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.01 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. using System.IO;
  7. using System.Text;
  8.  
  9. namespace lab4Masivi
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. //int suma = 0;
  16. //int j;
  17. //// начальное значение
  18. //string strValue;
  19. //int[] iArray = new int[20];
  20. //for (j = 0; j < 20; j++)
  21. //{
  22. // Console.Write("[" + j + "]" + " "); /////RABOTAET
  23. // strValue = Console.ReadLine();
  24. // // ввод и присваивание значений
  25. // iArray[j] = Convert.ToInt32(strValue);
  26. //}
  27. //for (j = 0; j < 20; j++)
  28. //{
  29. // Console.Write(+iArray[j] + " ");
  30. // if (iArray[j] >= 0)
  31. // {
  32. // suma = suma + iArray[j];
  33. // }
  34. //}
  35. //Console.WriteLine("Сумма = " + suma);
  36. //Console.Read();
  37. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  38. //int temp;
  39. //int j, n;
  40. //n = 10;
  41. //string strValue;
  42. //int[] iArray = new int[n];
  43. //int[] jArray = new int[n];
  44. //for (j = 0; j < 10; j++)
  45. //{
  46. // Console.Write("[" + j + "]" + " ");
  47. // strValue = Console.ReadLine();
  48. // // ввод и присваивание значений
  49. // iArray[j] = Convert.ToInt32(strValue);
  50. //}
  51. //for (j = 0; j < n; j++)
  52. //{
  53. // Console.Write(+iArray[j] + " "); /////RABOTAET
  54. //}
  55. //Console.WriteLine();
  56. //for (j = 0; j < n / 2; j++)
  57. //{
  58. // temp = iArray[j];
  59. // iArray[j] = iArray[n - j - 1];
  60. // iArray[n - j - 1] = temp;
  61.  
  62. //}
  63.  
  64. //for (j = 0; j < n; j++)
  65. //{
  66. // Console.Write(+iArray[j] + " ");
  67. //}
  68. //Console.WriteLine();
  69. //Console.Read();
  70. /////////////////////////////////////////////////////////////////////////////////////////////////////////
  71. //написать процедуру. для заданного массив(4, 5), переставить местами столбец с наибольшим количеством нулевых эле-ментов и столбец последний по порядку следования в массиве .
  72. //int[,] ijArray = new int[4, 5];
  73. //int j;
  74. //int i;
  75. //for (i = 0; i < 4; i++)
  76. //{
  77. // for (j = 0; j < 5; j++)
  78. // {
  79. // Console.Write("masiv[" + i + "," + j + "]: ");
  80. // ijArray[i, j] = int.Parse(Console.ReadLine());
  81. // }
  82. //}
  83. //for (i = 0; i < 4; i++)
  84. //{
  85. // for (j = 0; j < 5; j++)
  86. // {
  87. // Console.Write(" " + ijArray[i, j]);
  88. // }
  89. // Console.WriteLine();
  90. //}
  91. //Console.WriteLine();
  92. //Console.WriteLine();
  93. //int nuley = 0;
  94. //int proverka = 0;
  95. //int ii = 0;
  96. //int jj;
  97. //for (i = 0; i < 5; i++)
  98. //{
  99. // nuley = 0;
  100. // for (j = 0; j < 4; j++)
  101. // {
  102. // if (ijArray[j, i] == 0)
  103. // {
  104. // nuley++;
  105. // }
  106. // } // pol rublya
  107. // if (proverka < nuley)
  108. // {
  109. // proverka = nuley;
  110.  
  111. // ii = i;
  112. // }
  113. //}
  114.  
  115.  
  116. //int temp;
  117.  
  118. //for (i = 0; i < 4; i++) //отсортированный
  119. //{
  120. // for (j = 0; j < 5; j++)
  121. // {
  122. // if (j == ii)
  123. // {
  124. // temp = ijArray[i, j];
  125. // ijArray[i, j] = ijArray[i, 4];
  126. // ijArray[i, 4] = temp;
  127.  
  128.  
  129. // }
  130. // }
  131. //}
  132.  
  133. //var writePath = @"\\main\RDP\32П\МихайловВА\Desktop\VAZ.txt";
  134. //try
  135. //{
  136. // using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
  137. // {
  138. // for (i = 0; i < 4; i++)
  139. // {
  140. // for (j = 0; j < 5; j++)
  141. // {
  142. // sw.Write(" " + ijArray[i, j]);
  143. // }
  144. // sw.WriteLine();
  145. // }
  146. // }
  147.  
  148.  
  149. // Console.WriteLine("Запись выполнена");
  150. // Console.Read();
  151. //}
  152. //catch (Exception e)
  153. //{
  154. // Console.WriteLine(e.Message);
  155. //}
  156.  
  157. //Console.Read();
  158. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  159. int n;
  160.  
  161. string str;
  162. Console.WriteLine("Введите размерность матрицы");
  163.  
  164. n = Convert.ToInt32(Console.ReadLine());
  165.  
  166. int[,] A = new int[n, n];
  167.  
  168.  
  169.  
  170. Console.WriteLine("Введите элементы матрицы");
  171. for (int i = 0; i < n; i++)
  172. {
  173. for (int j = 0; j < n; j++)
  174. {
  175. str = Console.ReadLine();
  176. A[i, j] = Convert.ToInt32(str);
  177.  
  178.  
  179. }
  180. Console.WriteLine();
  181.  
  182. }
  183.  
  184.  
  185. Console.WriteLine("Матрица");
  186. for (int i = 0; i < n; i++)
  187. {
  188. for (int j = 0; j < n; j++)
  189.  
  190. Console.Write("{0,5}", A[i, j]);
  191. Console.WriteLine();
  192. }
  193. Console.WriteLine();
  194. int sum = 0;
  195. int sumS = 0;
  196. int kol = n - 1;
  197. int[] iArray = new int[2 * A.GetLength(0) - 1];
  198. for (int i = 0; i < n; i++)
  199. {
  200. sum = 0; sumS = 0;
  201. for (int j = 0; j <= i; j++)
  202. {
  203. if (kol != 0)
  204. {
  205. sum += A[n - 1 - i + j, j];
  206. sumS += A[j, n - 1 - i + j];
  207. }
  208.  
  209. }
  210. iArray[i] = sum;
  211. iArray[iArray.Length - i - 1] = sumS;
  212. kol--;
  213. }
  214. for (int j = 0; j < 2 * A.GetLength(0) - 1; j++)
  215. {
  216. if (+iArray[j] != 0)
  217. {
  218. Console.Write(+iArray[j] + " ");
  219. }
  220. }
  221. var writePath = @"C:\Users\theve\OneDrive\Desktop\VAZ.txt";
  222. try
  223. {
  224. using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
  225. {
  226. sw.WriteLine("Матрица");
  227. for (int i = 0; i < n; i++)
  228. {
  229. for (int j = 0; j < n; j++)
  230.  
  231. sw.Write("{0,5}", A[i, j]);
  232. sw.WriteLine();
  233. }
  234. sw.WriteLine();
  235. for (int j = 0; j < 2 * A.GetLength(0) - 1; j++)
  236. {
  237. if (+iArray[j] != 0)
  238. {
  239. sw.Write(+iArray[j] + " ");
  240. }
  241. }
  242. }
  243. Console.WriteLine("Запись выполнена");
  244. }
  245. catch (Exception e)
  246. {
  247. Console.WriteLine(e.Message);
  248. }
  249. Console.Read();
  250.  
  251. // Для заданного двумерного массива размером N×N просумми-ровать элементы, расположенные на диагоналях, параллельных главной. Результаты поместить в одномерный массив.
  252. }
  253.  
  254. }
  255. }
  256.  
  257. //using System;
  258. //using System.Collections.Generic;
  259. //using System.IO;
  260. //using System.Linq;
  261. //using System.Text;
  262. //using System.Threading.Tasks;
  263.  
  264. //namespace VivodvTXT
  265. //{
  266. // class Program
  267. // {
  268. // static void Main(string[] args)
  269. // {
  270. // string s;
  271. // double x, y;
  272. // StreamWriter f = new StreamWriter("C:\\Users\\theve\\OneDrive\\Desktop\\out.txt");
  273. // StreamReader f1 = new StreamReader("C:\\Users\\theve\\OneDrive\\Desktop\\in.txt");
  274. // f.WriteLine("Таблица значений");
  275. // f.WriteLine("+---------------------------------------+");
  276. // f.WriteLine("+Аргумент + Функция +");
  277. // f.WriteLine("+---------------------------------------+");
  278. // metka: s = f1.ReadLine();
  279. // if (s == null) goto metka1;
  280. // x = Convert.ToDouble(s);
  281. // y = 2 - ((Math.Exp(2 * x) + Math.Exp(-2 * x)) / (Math.Exp(2) + Math.Exp(-2)));
  282.  
  283.  
  284. // f.WriteLine("+ X = {0:F3} + Y = {1:e3} +\n", x, y);
  285. // goto metka;
  286. // metka1:
  287. // f.WriteLine("+---------------------------------------+");
  288. // f.WriteLine("Составил: Михайлов В.А. 32П {0} \n", s);
  289. // f.Close();
  290. // f1.Close();
  291. // }
  292. // }
  293. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement