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 p05_Vect2
- {
- class Program
- {
- static void Main(string[] args)
- {
- //diverse op pe vect
- int[] a;
- int i, n;
- Console.Write("n = ");
- n = int.Parse(Console.ReadLine());
- // gen aleatoare a elem vectorului
- a = new int[n];
- Random r = new Random();
- for (i = 0; i < n; i++)
- a[i] = r.Next(100); // se gen un nr natural cuprins intre 0 si 99
- Console.Write("\nDiversre mod de afisare a vectorului\n");
- // 1.
- for (i = 0; i < n; i++)
- Console.Write(a[i] + " ");
- Console.WriteLine();
- // 2.
- for (i = 0; i < a.Length; i++)
- Console.Write(a[i] + " ");
- Console.WriteLine();
- //3.
- foreach (var x in a)
- {
- Console.Write(x + " ");
- }
- Console.WriteLine();
- Array.Sort(a);
- foreach (var x in a)
- {
- Console.Write(x + " ");
- }
- Console.WriteLine();
- int find = Array.BinarySearch(a, 1050);
- if (find < 0) Console.WriteLine("Nu exista");
- else Console.WriteLine("Pozitia" + find);
- ///vect initializati la declarare
- /////vectori de constante
- int[] t = new int [10] {0, 1, 2, 3, 4, 5, 6 ,7 ,8 ,9 };
- foreach (var y in t)
- Console.Write(y +" ");
- Console.WriteLine();
- int[] v = new int [10] {0, 1, 2, 3, 4, 5, 6 ,7 ,8 ,9 };
- foreach (var e in v)
- Console.Write(e +" ");
- Console.WriteLine();
- int[] s = new int [10] {0, 1, 2, 3, 4, 5, 6 ,7 ,8 ,9 };
- foreach (var e in s)
- Console.Write(e +" ");
- Console.WriteLine();
- /// parcuregea de la drepata la stanga a vect s;
- for(i = s.Length - 1; i >= 0; i--)
- Console.Write(s[i] + " ");
- Console.WriteLine();
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement