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;
- namespace laba_5
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Введите номер задания");
- int z = Convert.ToInt32(Console.ReadLine());
- switch (z)
- {
- case (1):
- Console.WriteLine("Введите размерность");
- Task1.arr(Convert.ToInt32(Console.ReadLine()));
- break;
- case (2):
- Console.WriteLine("Введите размерность");
- Task2.sumArr(Convert.ToInt32(Console.ReadLine()));
- break;
- case (3):
- Console.WriteLine("Введите размерность");
- Task3.strArr(Convert.ToInt32(Console.ReadLine()), Convert.ToInt32(Console.ReadLine()));
- break;
- case (4):
- Task4.matrix();
- break;
- }
- Console.ReadKey();
- }
- }
- static class Task1
- {
- public static void arr(int q)
- {
- int[] myArr = new int[q];
- for (int i = 0; i < myArr.Length; i++)
- {
- Console.Write("Введите {0} элемент ", i + 1);
- myArr[i] = Int32.Parse(Console.ReadLine());
- }
- int p = 0;
- foreach (int n in myArr.SkipWhile(x => x != 0).Skip(1).TakeWhile(x => x != 0))
- p += n;
- Console.WriteLine(p);
- return;
- }
- }
- static class Task2
- {
- public static void sumArr(int q)
- {
- int sum = 0;
- int[] a = new int[q];
- for (int i = 0; i < q; i++)
- {
- Console.Write("Введите {0} элемент ", i + 1);
- a[i] = Int32.Parse(Console.ReadLine());
- }
- for (int i = q - 1; i >= 0; i--)
- {
- if (a[i] != 0) sum += a[i];
- else break;
- }
- Console.WriteLine("Сумма равна: " + sum);
- Console.ReadLine();
- }
- }
- static class Task3
- {
- public static void strArr(int n, int m)
- {
- int strings = 0;
- int[,] myArr = new int[n, m];
- int[] s = new int[n];
- int i = 0, j = 0;
- Console.WriteLine("Заполни матрицу");
- for (i = 0; i < n; i++)
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < m; j++)
- {
- Console.Write("mas[" + i + "," + j + "]: ");
- myArr[i, j] = int.Parse(Console.ReadLine());
- }
- }
- Console.WriteLine();
- for (i = 0; i < n; i++)
- {
- for (j = 0; j < m; j++)
- {
- Console.Write(" myArr[" + i + "," + j + "]: " + myArr[i, j] + "\t");
- }
- Console.WriteLine();
- }
- Console.WriteLine("Строки в которых один нулевой элемент: ");
- for (i = 0; i < n; i++)
- {
- int k = 0;
- for (j = 0; j < m; j++)
- {
- if (myArr[i, j] == 0)
- {
- k++;
- strings += 1;
- }
- if (k == 1)
- {
- break;
- }
- }
- }
- Console.WriteLine("Сумма колличества строк = {0}",strings);
- }
- }
- static class Task4
- {
- public static void matrix()
- {
- Random rnd = new Random();
- int[,] matrix = new int[5, 5];
- for (int i = 0; i < matrix.GetLength(0); i++)
- {
- for (int j = 0; j < matrix.GetLength(1); j++)
- {
- Console.Write(matrix[i, j] = rnd.Next(10));
- Console.Write("\t");
- }
- Console.WriteLine();
- }
- int? max = null;
- for (int i = 1 - matrix.GetLength(1); i < matrix.GetLength(1); i++)
- {
- int sum = 0;
- int j = i < 0 ? -i : 0;
- int k = i < 0 ? 0 : i;
- while (j < matrix.GetLength(0) && k < matrix.GetLength(1))
- {
- sum += matrix[j++, k++];
- }
- Console.WriteLine(sum);
- if (max == null || sum > max) { max = sum; }
- }
- Console.WriteLine(max);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement