Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Text;
- namespace lab4Masivi
- {
- class Program
- {
- static void Main(string[] args)
- {
- //int suma = 0;
- //int j;
- //// начальное значение
- //string strValue;
- //int[] iArray = new int[20];
- //for (j = 0; j < 20; j++)
- //{
- // Console.Write("[" + j + "]" + " "); /////RABOTAET
- // strValue = Console.ReadLine();
- // // ввод и присваивание значений
- // iArray[j] = Convert.ToInt32(strValue);
- //}
- //for (j = 0; j < 20; j++)
- //{
- // Console.Write(+iArray[j] + " ");
- // if (iArray[j] >= 0)
- // {
- // suma = suma + iArray[j];
- // }
- //}
- //Console.WriteLine("Сумма = " + suma);
- //Console.Read();
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //int temp;
- //int j, n;
- //n = 10;
- //string strValue;
- //int[] iArray = new int[n];
- //int[] jArray = new int[n];
- //for (j = 0; j < 10; j++)
- //{
- // Console.Write("[" + j + "]" + " ");
- // strValue = Console.ReadLine();
- // // ввод и присваивание значений
- // iArray[j] = Convert.ToInt32(strValue);
- //}
- //for (j = 0; j < n; j++)
- //{
- // Console.Write(+iArray[j] + " "); /////RABOTAET
- //}
- //Console.WriteLine();
- //for (j = 0; j < n / 2; j++)
- //{
- // temp = iArray[j];
- // iArray[j] = iArray[n - j - 1];
- // iArray[n - j - 1] = temp;
- //}
- //for (j = 0; j < n; j++)
- //{
- // Console.Write(+iArray[j] + " ");
- //}
- //Console.WriteLine();
- //Console.Read();
- /////////////////////////////////////////////////////////////////////////////////////////////////////////
- //написать процедуру. для заданного массив(4, 5), переставить местами столбец с наибольшим количеством нулевых эле-ментов и столбец последний по порядку следования в массиве .
- //int[,] ijArray = new int[4, 5];
- //int j;
- //int i;
- //for (i = 0; i < 4; i++)
- //{
- // for (j = 0; j < 5; j++)
- // {
- // Console.Write("masiv[" + i + "," + j + "]: ");
- // ijArray[i, j] = int.Parse(Console.ReadLine());
- // }
- //}
- //for (i = 0; i < 4; i++)
- //{
- // for (j = 0; j < 5; j++)
- // {
- // Console.Write(" " + ijArray[i, j]);
- // }
- // Console.WriteLine();
- //}
- //Console.WriteLine();
- //Console.WriteLine();
- //int nuley = 0;
- //int proverka = 0;
- //int ii = 0;
- //int jj;
- //for (i = 0; i < 5; i++)
- //{
- // nuley = 0;
- // for (j = 0; j < 4; j++)
- // {
- // if (ijArray[j, i] == 0)
- // {
- // nuley++;
- // }
- // } // pol rublya
- // if (proverka < nuley)
- // {
- // proverka = nuley;
- // ii = i;
- // }
- //}
- //int temp;
- //for (i = 0; i < 4; i++) //отсортированный
- //{
- // for (j = 0; j < 5; j++)
- // {
- // if (j == ii)
- // {
- // temp = ijArray[i, j];
- // ijArray[i, j] = ijArray[i, 4];
- // ijArray[i, 4] = temp;
- // }
- // }
- //}
- //var writePath = @"\\main\RDP\32П\МихайловВА\Desktop\VAZ.txt";
- //try
- //{
- // using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
- // {
- // for (i = 0; i < 4; i++)
- // {
- // for (j = 0; j < 5; j++)
- // {
- // sw.Write(" " + ijArray[i, j]);
- // }
- // sw.WriteLine();
- // }
- // }
- // Console.WriteLine("Запись выполнена");
- // Console.Read();
- //}
- //catch (Exception e)
- //{
- // Console.WriteLine(e.Message);
- //}
- //Console.Read();
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- int n;
- string str;
- Console.WriteLine("Введите размерность матрицы");
- n = Convert.ToInt32(Console.ReadLine());
- int[,] A = new int[n, n];
- Console.WriteLine("Введите элементы матрицы");
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- {
- str = Console.ReadLine();
- A[i, j] = Convert.ToInt32(str);
- }
- Console.WriteLine();
- }
- Console.WriteLine("Матрица");
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- Console.Write("{0,5}", A[i, j]);
- Console.WriteLine();
- }
- Console.WriteLine();
- int sum = 0;
- int sumS = 0;
- int kol = n - 1;
- int[] iArray = new int[2 * A.GetLength(0) - 1];
- for (int i = 0; i < n; i++)
- {
- sum = 0; sumS = 0;
- for (int j = 0; j <= i; j++)
- {
- if (kol != 0)
- {
- sum += A[n - 1 - i + j, j];
- sumS += A[j, n - 1 - i + j];
- }
- }
- iArray[i] = sum;
- iArray[iArray.Length - i - 1] = sumS;
- kol--;
- }
- for (int j = 0; j < 2 * A.GetLength(0) - 1; j++)
- {
- if (+iArray[j] != 0)
- {
- Console.Write(+iArray[j] + " ");
- }
- }
- var writePath = @"C:\Users\theve\OneDrive\Desktop\VAZ.txt";
- try
- {
- using (StreamWriter sw = new StreamWriter(writePath, false, System.Text.Encoding.Default))
- {
- sw.WriteLine("Матрица");
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < n; j++)
- sw.Write("{0,5}", A[i, j]);
- sw.WriteLine();
- }
- sw.WriteLine();
- for (int j = 0; j < 2 * A.GetLength(0) - 1; j++)
- {
- if (+iArray[j] != 0)
- {
- sw.Write(+iArray[j] + " ");
- }
- }
- }
- Console.WriteLine("Запись выполнена");
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- }
- Console.Read();
- // Для заданного двумерного массива размером N×N просумми-ровать элементы, расположенные на диагоналях, параллельных главной. Результаты поместить в одномерный массив.
- }
- }
- }
- //using System;
- //using System.Collections.Generic;
- //using System.IO;
- //using System.Linq;
- //using System.Text;
- //using System.Threading.Tasks;
- //namespace VivodvTXT
- //{
- // class Program
- // {
- // static void Main(string[] args)
- // {
- // string s;
- // double x, y;
- // StreamWriter f = new StreamWriter("C:\\Users\\theve\\OneDrive\\Desktop\\out.txt");
- // StreamReader f1 = new StreamReader("C:\\Users\\theve\\OneDrive\\Desktop\\in.txt");
- // f.WriteLine("Таблица значений");
- // f.WriteLine("+---------------------------------------+");
- // f.WriteLine("+Аргумент + Функция +");
- // f.WriteLine("+---------------------------------------+");
- // metka: s = f1.ReadLine();
- // if (s == null) goto metka1;
- // x = Convert.ToDouble(s);
- // y = 2 - ((Math.Exp(2 * x) + Math.Exp(-2 * x)) / (Math.Exp(2) + Math.Exp(-2)));
- // f.WriteLine("+ X = {0:F3} + Y = {1:e3} +\n", x, y);
- // goto metka;
- // metka1:
- // f.WriteLine("+---------------------------------------+");
- // f.WriteLine("Составил: Михайлов В.А. 32П {0} \n", s);
- // f.Close();
- // f1.Close();
- // }
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement