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 Lab4
- {
- class Program
- {
- static void Main(string[] args)
- //// Написать программу для определения количества положительных элементов, заданного массива А, состоящего из 20-ти элементов.
- //{
- // int[] A = new int[20];
- // int dsa = 0;
- // Console.WriteLine("Введите элементы");
- // for (int i = 0; i < 20; i++)
- // A[i] = int.Parse(Console.ReadLine());
- // for (int a = 0; a < 20; a++)
- // if (A[a] > 0)
- // dsa++;
- // Console.ReadKey(true);
- // Console.WriteLine("Количество положительных элементов одномерного массива - {0}", dsa);
- // Console.Read();
- //}
- //Задан массив А. Поместить положительные элементы этого массива в массив В,А отрицательные в массив С.
- //{
- // int n = 20;
- // int[] array = new int[n];
- // Random rand = new Random();
- // List<int> B = new List<int>();
- // List<int> C = new List<int>();
- // for (int i = 0; i < n; i++)
- // {
- // array[i] = rand.Next(-10, 10);
- // Console.Write(array[i] + " ");
- // if (array[i] > 0)
- // {
- // B.Add(array[i]);
- // }
- // else
- // {
- // C.Add(array[i]);
- // }
- // }
- // Console.WriteLine();
- // Console.WriteLine(String.Join(" ", B));
- // Console.WriteLine(String.Join(" ", C));
- // Console.ReadKey();
- //}
- ////Написать процедуру для вывода на печать отрицательных элементов, лежащих на главной диагонали заданного массива A(4,4).
- {
- int[,] arr = new int[4, 4];
- int otricznach = 0;
- Console.WriteLine("Введите элементы:");
- for (int i = 0; i <= arr.GetLength(0) - 1; i++)
- for (int j = 0; j <= arr.GetLength(1) - 1; j++)
- arr[i, j] = int.Parse(Console.ReadLine());
- Console.WriteLine("\n______________________________\n");
- for (int a = 0; a <= arr.GetLength(0) - 1; a++)
- {
- for (int b = 0; b <= arr.GetLength(1) - 1; b++)
- Console.Write($"{arr[a, b]}\t");
- Console.WriteLine();
- }
- Console.WriteLine("\n______________________________\n");
- for (int c = 0; c <= arr.GetLength(0) - 1; c++)
- {
- for (int d = 0; d <= arr.GetLength(1) - 1; d++)
- {
- if ((d == c) && (arr[c, d] < 0))
- {
- otricznach++;
- Console.Write($"{arr[c, d]}\t");
- }
- }
- }
- Console.WriteLine("\n\n{0} Отрицательные", otricznach);
- Console.ReadKey(true);
- }
- //Задан массив размером 16. Сформировать из него массив размером 4х4 по строкам.
- //{
- // string input = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16";
- // string[] str = input.Split(' ');
- // int count = 0, p = 0; ;
- // int[,] mas = new int[4, 4];
- // for (int i = 0; i <= mas.GetLength(0) - 1; i++)
- // {
- // for (int j = 0; j <= mas.GetLength(1) - 1; j++)
- // {
- // if (count < 4) { mas[i, j] = int.Parse(str[p]); count++; p++; }
- // else break;
- // }
- // count = 0;
- // Console.WriteLine("{0} {1} {2} {3}", mas[i, 0], mas[i, 1], mas[i, 2], mas[i, 3]);
- // }Console.Read();
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement