Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- /* Ситуативно, для чтения
- * foreach (int i in nums)
- {
- Console.WriteLine(i);
- }
- int[,] mas = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
- int rows = mas.GetUpperBound(0) + 1;
- int columns = mas.Length / rows;
- // или так
- // int columns = mas.GetUpperBound(1) + 1;
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < columns; j++)
- {
- Console.Write(mas[i, j]);
- Console.Write("\t");
- }
- Console.WriteLine();
- }*/
- /* Задан массив действительных чисел размерности 10х10.Найти суммы элементов каждой строки, произведения элементов каждого столбца,
- * и максимальный элемент главной диагонали.*/
- /* var rnd = new Random();
- int[,] arr = new int[10, 10];
- int sum ;
- for (int i = 0; i < 10; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- arr[i, j] = rnd.Next(1, 9);
- Console.Write(arr[i, j]);
- Console.Write("\t");
- }
- Console.WriteLine();
- }
- for (int i = 0; i < 10; i++)
- {
- sum = 0;
- for (int j = 0; j < 10; j++)
- {
- sum += arr[i, j];
- }
- Console.WriteLine(" sum= " + sum);
- }
- int comp=1;
- for (int i = 0; i < 10; i++)
- {
- comp = 1;
- for (int j = 0; j < 10; j++)
- {
- comp*= arr[j, i];
- }
- Console.WriteLine(" composition= " + comp);
- }
- int a = 0;
- int b = 0;
- int max=0;
- for ( a = 0 , b=0; a < 9 && b<9; a++,b++)
- {
- if (arr[a,b] >arr [a+1,b+1] )
- {
- max = arr[a, b];
- arr[a, b] = arr[a + 1, b + 1];
- arr[a + 1, b + 1] = max;
- }
- }
- Console.WriteLine("maximum= "+arr[9,9]);*/
- int res = 0;
- int[] mas = new int[20];
- int[] m = new int[20];
- var rnd = new Random();
- for (int i = 0; i < 20; i++)
- {
- mas[i] = rnd.Next(-1999, 1999);
- }
- for (int i = 0; i < 20; i++)
- {
- if (mas[i] <= 888)
- {
- res = res + 1;
- m[i] = mas[i];
- }
- }
- foreach (int i in mas)
- {
- Console.Write(" "+i);
- }
- Console.WriteLine();
- foreach (int i in m)
- {
- Console.Write(" " + i);
- }
- Console.WriteLine();
- int[] b = new int[res+1];
- int q = 0;
- for (int i = 0; i < 20; i++)
- {
- int k = m[i];
- if (k != 0)
- {
- b[q] = k;
- q = q + 1;
- }
- }
- int max = 0;
- for (int a = 0; a < res; a++)
- {
- for (int c = 0; c < res-1; c++)
- {
- if (b[c] < b[c + 1])
- {
- max = b[c];
- b[c] = b[c + 1];
- b[c + 1] = max;
- }
- }
- }
- for (int a = 0; a < res; a++)
- {
- Console.Write(b[a] + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement