Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Alpha_Task_1
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] arr = new int[5];
- int number;
- Console.WriteLine("Give me an array from 5 elements:");
- for(int i=0; i<arr.Length;i++)
- {
- arr[i] = Int32.Parse(Console.ReadLine());
- }
- Console.WriteLine("Give me a number:");
- number = Int32.Parse(Console.ReadLine());
- int temp;
- for(int i=0;i<arr.Length;i++)
- {
- {
- for(int j=0; j<arr.Length-1; j++)
- {
- if(arr[j]>arr[j+1])
- {
- temp = arr[j];
- arr[j] = arr[j+1];
- arr[j+1] = temp;
- }
- }
- }
- }
- Console.Write("Sort array: ");
- for (int i = 0; i < arr.Length; i++)
- {
- Console.Write(arr[i]+" ");
- }
- Console.WriteLine();
- Bsearch(arr, number);
- }
- public static void Bsearch(int[] sort_arr, int x)
- {
- int count = 0;
- int index;
- for(int i=0; i<sort_arr.Length; i++)
- {
- if (count==0)
- {
- if (sort_arr[i] < x)
- {
- count++;
- index = i;
- Console.WriteLine($"Index: {index}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement