Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Alpha_Task_1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] arr = new int[5];
  14. int number;
  15.  
  16. Console.WriteLine("Give me an array from 5 elements:");
  17. for(int i=0; i<arr.Length;i++)
  18. {
  19. arr[i] = Int32.Parse(Console.ReadLine());
  20. }
  21.  
  22. Console.WriteLine("Give me a number:");
  23. number = Int32.Parse(Console.ReadLine());
  24.  
  25. int temp;
  26. for(int i=0;i<arr.Length;i++)
  27. {
  28. {
  29. for(int j=0; j<arr.Length-1; j++)
  30. {
  31. if(arr[j]>arr[j+1])
  32. {
  33. temp = arr[j];
  34. arr[j] = arr[j+1];
  35. arr[j+1] = temp;
  36. }
  37. }
  38. }
  39. }
  40.  
  41. Console.Write("Sort array: ");
  42. for (int i = 0; i < arr.Length; i++)
  43. {
  44. Console.Write(arr[i]+" ");
  45. }
  46. Console.WriteLine();
  47.  
  48. Bsearch(arr, number);
  49. }
  50.  
  51. public static void Bsearch(int[] sort_arr, int x)
  52. {
  53. int count = 0;
  54. int index;
  55.  
  56. for(int i=0; i<sort_arr.Length; i++)
  57. {
  58. if (count==0)
  59. {
  60. if (sort_arr[i] < x)
  61. {
  62. count++;
  63. index = i;
  64. Console.WriteLine($"Index: {index}");
  65. }
  66. }
  67. }
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement