Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class BinarySearch
- {
- static void Main()
- {
- int[] array = { 1, 3, 5, 12, 88, 4, 22, 16};
- foreach (int num in array)
- {
- Console.Write(num + " ");
- }
- Console.WriteLine();
- Console.WriteLine("Sorted Array");
- Array.Sort(array);
- foreach (int num in array)
- {
- Console.Write(num + " ");
- }
- Console.Write("Binary Search for(enter number): ");
- int number = int.Parse(Console.ReadLine());
- for (int i = 0; i < array.Length; i++)
- {
- if (number == array[i])
- {
- Console.WriteLine("Your number is at position {0}", i);
- }
- else if (number != array[i] && (i == array.Length - 1))
- {
- Console.WriteLine("There is no such number!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement