﻿ C# Sharp exercises: Find the pair of adjacent elements that has the highest product of an given array of integers - w3resource

# C# Sharp Exercises: Find the pair of adjacent elements that has the highest product of an given array of integers

## C# Sharp Basic: Exercise-57 with Solution

Write a C# program to find the pair of adjacent elements that has the highest product of an given array of integers.

Sample Solution:

C# Sharp Code:

``````using System;
public class Example
{

{
int max = 0;
for (int i=1; i<input_Array.Length; ) {
max = Math.Max(max, input_Array[i-1] * input_Array[i++]);
}
return max;
}

public static void Main()
{
Console.WriteLine(adjacent_Elements_Product(new int[] {1 , 3, 4, 5, 2}));
Console.WriteLine(adjacent_Elements_Product(new int[] {1 , 3, -4, 5, 2}));
Console.WriteLine(adjacent_Elements_Product(new int[] {1 , 0, -4, 0, 2}));
}
}
``````

Sample Output:

```20
10
0
```

Flowchart:

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

What is the difficulty level of this exercise?

﻿

New Content: Composer: Dependency manager for PHP, R Programming