Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TestForAlfa
- {
- class Program
- {
- static void Main(string[] args)
- {
- const int lenArr = 10;
- int[] myArray = new int[lenArr];
- int X, i, ind;
- Random rnd = new Random();
- X = rnd.Next(-lenArr, 10);
- Console.WriteLine("X = " + X);
- Console.WriteLine("Initial data:\n");
- for (i = 0; i < lenArr; i++)
- {
- myArray[i] = rnd.Next(lenArr*2);
- Console.Write(myArray[i] + " ");
- }
- Array.Sort(myArray);
- Array.Reverse(myArray);
- Console.WriteLine();
- Console.WriteLine("Sorted array:\n");
- for (i = 0; i < myArray.Length; i++)
- {
- Console.Write(myArray[i] + " ");
- }
- Console.WriteLine();
- if ((ind = bSearch(myArray, X)) != -1)
- Console.WriteLine("min index = " + ind);
- else
- Console.WriteLine("There is no element less than X.");
- Console.Read();
- int bSearch(int[] arr, int x)
- {
- int minInd = 0;
- for (int j = 1; j < arr.Length; j++)
- {
- if (arr[j] < x)
- {
- minInd = j;
- }
- }
- if (minInd == 0)
- return -1;
- return minInd+1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement