-
Notifications
You must be signed in to change notification settings - Fork 0
/
MontainerRangeII.cs
53 lines (50 loc) · 1.39 KB
/
MontainerRangeII.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DoubleDivision
{
internal class MontainerRangeII
{
static void MainNB()
{
int a;
Console.Write("Enter n = ");
a = int.Parse(Console.ReadLine());
int[] height = new int[a];
for (int i = 0; i < height.Length; i++)
{
Console.Write($"Enter a[{i}] = ");
height[i] = int.Parse(Console.ReadLine());
}
int peaks = 0;
for (int i = 0; i < height.Length; i++)
{
if (i==0)
{
if (height[0] > height[1])
{
peaks++;
i++;
}
}
else if (i== height.Length -1)
{
if (height[i]> height[i-1])
peaks++;
}
else
{
if (height[i] > height[i-1] && height[i] > height[i+1])
{
peaks++;
i++;
}
}
}
Console.WriteLine($"Height mountain is: {peaks}");
Console.ReadKey();
}
}
}