Advertisement
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[] array = new int[10];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = rand.Next(0, 10);
- Console.Write("{0} ", array[i]);
- }
- Console.WriteLine();
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == 0)
- array[i] = -1;
- }
- array = array.OrderBy(n => n == -1).ToArray();
- foreach (int item in array)
- Console.Write("{0} ", item);
- Console.ReadKey();
- Console.Clear();
- }
- private static void Second()
- {
- int[] array = new int[20];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = rand.Next(-10, 30);
- Console.Write("{0} ", array[i]);
- }
- Console.WriteLine();
- int sum = 0;
- int begin = Array.FindIndex(array, n => n < 0);
- if (begin != -1 && begin != array.Length - 1)
- {
- begin++;
- for (int i = begin; i < array.Length; i++)
- sum += array[i];
- }
- Console.WriteLine(sum.ToString());
- Console.ReadKey();
- Console.Clear();
- }
- private static void Third()
- {
- int[] array = new int[20];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = rand.Next(-30, 10);
- Console.Write("{0} ", array[i]);
- }
- Console.WriteLine();
- int sum = 0;
- int begin = Array.FindIndex(array, n => n > 0);
- if (begin != -1 && begin != array.Length - 1)
- {
- begin++;
- for (int i = begin; i < array.Length; i++)
- sum += array[i];
- }
- Console.WriteLine(sum.ToString());
- Console.ReadKey();
- Console.Clear();
- }
- private static void Fourth()
- {
- int[] array = new int[20];
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = rand.Next(-10, 10);
- Console.Write("{0} ", array[i]);
- }
- Console.WriteLine();
- int min = array[0];
- int minIndex = 0;
- int max = array[0];
- int maxIndex = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] < min)
- {
- min = array[i];
- minIndex = i;
- }
- else if (array[i] > max)
- {
- max = array[i];
- maxIndex = i;
- }
- }
- Console.WriteLine("{0}, {1}, {2}, {3}", min, minIndex, max, maxIndex);
- Console.ReadKey();
- Console.Clear();
- }
- public static void Main()
- {
- First();
- Second();
- Third();
- Fourth();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement