Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 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 ConsoleApp3
  8. {
  9. class Program
  10. {
  11.  
  12. static int bSearch (IEnumerable<int> array , int x)
  13. {
  14. int count = 0;
  15. int index =0;
  16. foreach ( int i in array ){
  17. if (i < x)
  18. {
  19. count++;
  20. index = count;
  21. IsFind = true;
  22.  
  23. break;
  24.  
  25. }
  26. else
  27. {
  28.  
  29. index = -1;
  30. }
  31. }
  32.  
  33. return index ;
  34. }
  35. static bool IsFind = false;
  36. static void Main(string[] args)
  37. {
  38. int[] SomeNumbers = new int[] { 51, 15, 6, 16, 74, 83, 243, 72, 2, 34, 6, 7, 8, 62, 42 };
  39. IEnumerable<int> SortedNumver = from i in SomeNumbers
  40. orderby i descending
  41.  
  42. select i;
  43.  
  44. int index = bSearch(SomeNumbers, 10);
  45. if (IsFind)
  46. Console.WriteLine($"Индекс:{index.ToString()}");
  47. else
  48. Console.WriteLine("Значение не найдено");
  49.  
  50.  
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement