In a one-dimensional array of 5 integers, find the element maximum by value and its index. Output the result to the screen.

C # language

Random r = new Random (); // pseudo-random class declaration
int [] array = new int [5]; // array declaration

for (int i = 0; i <array.Length; i ++) // filling the array with random numbers
{
array [i] = r.Next (0.101);
Console.WriteLine (array [i]); // output the array to the console
}

int max = array [0];
int indexMax = 0;

for (int i = 1; i <array.Length; i ++) // find the maximum element and its index
{
if (max <array [i])
{
max = array [i];
indexMax = i;
}
}

Console.WriteLine (“Maximum item:” + max + “\ r \ nEth index:” + indexMax); //output
Console.ReadLine (); // read from the console (otherwise it will close)



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.