Untitled

 avatar
unknown
plain_text
25 days ago
845 B
2
Indexable
int n;
Console.WriteLine("Dati n:");
n=int.Parse(Console.ReadLine());
int[]a = new int[n];
   Random rnd = new Random();
for (int i = 0; i < n; i++)
{
    a[i] = rnd.Next(-20,20);
}
Console.WriteLine("Sau generat valorile:");
for (int i = 0;i < n; i++)
{
    Console.WriteLine(a[i]+ " ");
}
for (int j = 0;j<n-1; j++)
{
    for (int i = 0; i<n/2-1; i++)
    {
        if (a[i] > a[j])
        {
            int aux = a[i];
            a[i] = a[j];
            a[j] = aux; 
        }
    }
}





for ( int j = n/2; j < n;j++)
{
    for(int i = j+1;i<n;i++)
    {
        if (a[j] < a[i])
        {
            int aux = a[j];
            a[j] = a[i];
            a[i] = aux;
        }
    }
}
Console.WriteLine("Tabloul este corect");
for (int i = 0;i<n; i++)
{
    Console.WriteLine(a[i]+" ");
}
Editor is loading...
Leave a Comment