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 ConsoleApplication4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] A = { 3, 6, 7, 5, 3, 1, 7, 8, 9, 1, 4,6,2,7,9,2,7,3,2,2,6,4,2,7,3,5,3,7,8,2 };
- int indexMax = 0;
- for (int i = 0; i < A.Length; i++)
- {
- if (i==0 && i != A.Length)
- {
- if(A[i + 1] < A[i])
- {
- indexMax = indexMax + 1;
- }
- }
- else if (i != 0 && i == A.Length)
- {
- if (A[i - 1] < A[i])
- {
- indexMax = indexMax + 1;
- }
- }
- else if (i != 0 && i != A.Length)
- {
- if (A[i] > A[i - 1] && A[i] > A[i + 1])
- {
- indexMax = indexMax + 1;
- }
- }
- }
- Console.WriteLine("Количество локальных максимумов = " + indexMax);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement