A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C# program to find the pair of adjacent elements that has the largest product of an given array which is equal to a given value
Q:

Write a C# program to find the pair of adjacent elements that has the largest product of an given array which is equal to a given value

0

Write a C# program to find the pair of adjacent elements that has the largest product of an given array which is equal to a given value

Sample Output:

False
True
True
False

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class Exercise
    {
  public static int array_adjacent_elements_product(int[] input_array)
    {
    int array_index = 0;
    int product = input_array[array_index] * input_array[array_index + 1];

    array_index++;
    while (array_index + 1 < input_array.Length)
    {
        product = ((input_array[array_index] * input_array[array_index + 1]) > product) ?
                   (input_array[array_index] * input_array[array_index + 1]) :
                    product;
        array_index++;
    }

    return product;
}
        public static void Main()
        {
            Console.WriteLine(array_adjacent_elements_product(new int[] { 2, 4, 2, 6, 9, 3 }) == 27);
            Console.WriteLine(array_adjacent_elements_product(new int[] { 0, -1,-1, -2 }) == 2);
            Console.WriteLine(array_adjacent_elements_product(new int[] { 6, 1, 12, 3, 1, 4 }) == 36);
            Console.WriteLine(array_adjacent_elements_product(new int[] { 1, 4, 3, 0 }) == 16);
        }
    }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now