Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MainClass
- {
- public static void Main(string[] args)
- {
- int[] matrix = new int[30];
- Random rnd = new Random();
- int[] localmax = new int[0];
- bool maxfound = false;
- for (int i = 0; i < matrix.Length; i++)
- {
- matrix[i] = rnd.Next(0, 100);
- Console.Write(matrix[i] + " ");
- }
- Console.WriteLine();
- Console.WriteLine("Максимумы: ");
- for (int i = 0; i < matrix.Length ; i++)
- {
- switch (i)
- {
- case 0:
- if (matrix[i] > matrix[i + 1])
- {
- maxfound = true;
- }
- break;
- case 29:
- if (matrix[i] > matrix[i - 1])
- {
- maxfound = true;
- }
- break;
- default:
- if (matrix[i] > matrix[i - 1] && matrix[i] > matrix[i + 1])
- {
- maxfound = true;
- }
- break;
- }
- if (maxfound)
- {
- int m_length = localmax.Length;
- int[] tempmax = new int[m_length + 1];
- tempmax[tempmax.Length - 1] = matrix[i];
- localmax = tempmax;
- maxfound = false;
- Console.Write(localmax[m_length] + " ");
- }
- }
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement