Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 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 p05_Vect2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. //diverse op pe vect
  14. int[] a;
  15. int i, n;
  16.  
  17. Console.Write("n = ");
  18. n = int.Parse(Console.ReadLine());
  19.  
  20. // gen aleatoare a elem vectorului
  21. a = new int[n];
  22. Random r = new Random();
  23. for (i = 0; i < n; i++)
  24. a[i] = r.Next(100); // se gen un nr natural cuprins intre 0 si 99
  25. Console.Write("\nDiversre mod de afisare a vectorului\n");
  26. // 1.
  27. for (i = 0; i < n; i++)
  28. Console.Write(a[i] + " ");
  29. Console.WriteLine();
  30.  
  31. // 2.
  32. for (i = 0; i < a.Length; i++)
  33. Console.Write(a[i] + " ");
  34. Console.WriteLine();
  35. //3.
  36. foreach (var x in a)
  37. {
  38. Console.Write(x + " ");
  39. }
  40. Console.WriteLine();
  41.  
  42. Array.Sort(a);
  43. foreach (var x in a)
  44. {
  45. Console.Write(x + " ");
  46. }
  47. Console.WriteLine();
  48.  
  49. int find = Array.BinarySearch(a, 1050);
  50. if (find < 0) Console.WriteLine("Nu exista");
  51. else Console.WriteLine("Pozitia" + find);
  52.  
  53. ///vect initializati la declarare
  54. /////vectori de constante
  55. int[] t = new int [10] {0, 1, 2, 3, 4, 5, 6 ,7 ,8 ,9 };
  56.  
  57. foreach (var y in t)
  58. Console.Write(y +" ");
  59. Console.WriteLine();
  60.  
  61. int[] v = new int [10] {0, 1, 2, 3, 4, 5, 6 ,7 ,8 ,9 };
  62.  
  63. foreach (var e in v)
  64. Console.Write(e +" ");
  65. Console.WriteLine();
  66.  
  67. int[] s = new int [10] {0, 1, 2, 3, 4, 5, 6 ,7 ,8 ,9 };
  68.  
  69. foreach (var e in s)
  70. Console.Write(e +" ");
  71. Console.WriteLine();
  72.  
  73. /// parcuregea de la drepata la stanga a vect s;
  74. for(i = s.Length - 1; i >= 0; i--)
  75. Console.Write(s[i] + " ");
  76. Console.WriteLine();
  77.  
  78.  
  79. {
  80.  
  81. }
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement