Swap the maximum and minimum elements of an array.

C # language

int n = int.Parse (Console.ReadLine ()); // get the number of array elements from the console
Random r = new Random ();
int [] arr = new int [n];

for (int i = 0; i <n; i ++)
{
arr [i] = r.Next (101); // fill the array with random numbers from 0 to 100
}

int max = arr [0], min = arr [0];

for (int i = 0; i <n; i ++)
{
if (arr [i] <min) // find the minimum element
min = arr [i];
if (arr [i]> max) // find the maximum element
max = arr [i];
}

for (int i = 0; i <n; i ++)
{
Console.Write (arr [i] + “”); // print
}

Console.WriteLine (“\ r \ nMax:” + max); // display the maximum
Console.WriteLine (“Min:” + min); // display the minimum

Console.Read ();



One of the components of a person's success in our time is receiving modern high-quality education, mastering the knowledge, skills and abilities necessary for life in society. A person today needs to study almost all his life, mastering everything new and new, acquiring the necessary professional qualities.