Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Example
- {
- class MyApplication
- {
- static Random rand = new Random();
- private static void First()
- {
- int[] first = new int[5];
- for (int i = 0; i < first.Length; i++)
- {
- first[i] = rand.Next(0, 10);
- Console.Write("{0} ", first[i]);
- }
- Console.WriteLine();
- int[] second = new int[5];
- for (int i = 0; i < first.Length; i++)
- {
- second[i] = rand.Next(0, 10);
- Console.Write("{0} ", second[i]);
- }
- Console.WriteLine();
- int[] result = new int[10];
- for (int i = 0; i < first.Length; i++)
- {
- result[i * 2] = first[i];
- result[i * 2 + 1] = second[i];
- }
- foreach (int item in result)
- Console.Write("{0} ", item);
- Console.ReadKey();
- Console.Clear();
- }
- private static void Second()
- {
- int[] first = new int[20];
- for (int i = 0; i < first.Length; i++)
- {
- first[i] = rand.Next(-10, 10);
- Console.Write("{0} ", first[i]);
- }
- Console.WriteLine();
- int[] second = new int[20];
- int secondIndex = 0;
- foreach (var item in first)
- if (item > 0)
- second[secondIndex++] = item;
- foreach (var item in first)
- if (item == 0)
- second[secondIndex++] = item;
- foreach (var item in first)
- if (item < 0)
- second[secondIndex++] = item;
- foreach (int item in second)
- Console.Write("{0} ", item);
- Console.ReadKey();
- Console.Clear();
- }
- private static void Third()
- {
- int[,] array = new int[5, 5];
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- array[i, j] = rand.Next(-10, 40);
- Console.Write("{0,3} ", array[i, j]);
- }
- Console.WriteLine();
- }
- bool negative = false;
- int sum = 0;
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- if (array[j, i] < 0)
- {
- negative = true;
- break;
- }
- sum += array[j, i];
- }
- if (!negative)
- Console.WriteLine("{0} - {1}", i, sum);
- sum = 0;
- negative = false;
- }
- Console.ReadKey();
- Console.Clear();
- }
- private static void Fourth()
- {
- int[,] array = new int[5, 5];
- for (int i = 0; i < 5; i++)
- {
- for (int j = 0; j < 5; j++)
- {
- array[i, j] = rand.Next(-5, 5);
- Console.Write("{0,3} ", array[i, j]);
- }
- Console.WriteLine();
- }
- int positives = 0;
- int zeros = 0;
- foreach (var item in array)
- {
- if (item > 0)
- positives++;
- else if (item == 0)
- zeros++;
- }
- Console.WriteLine("+ - {0}, 0 - {1}", positives, zeros);
- }
- public static void Main()
- {
- First();
- Second();
- Third();
- Fourth();
- }
- }
- }
Add Comment
Please, Sign In to add comment