Last active
March 15, 2018 00:36
-
-
Save Villelmo/adcf4f5e232868d47294f82e2ec933a4 to your computer and use it in GitHub Desktop.
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Definition for arrays: | |
//typedef struct arr_integer{ | |
// int size; | |
// int arr*; | |
// } inputArray; | |
// arr_##name alloc_arr_##name(int len) { | |
// arr_##name a = {len, len > 0 ? malloc(sizeof(type) * len) : NULL}; | |
// return a; | |
// } | |
// | |
int adjacentElementsProduct(arr_integer inputArray) { | |
int i,j; // an even number and an odd number | |
int mult[30]; // store the result of the operation of numbers adjacent | |
// run for every array | |
for(i = 0, j = 0; i >= sizeof(inputArray) && j >= sizeof(inputArray);i++){ | |
j++; // flag odd number | |
// make the operation between adjacent numbers | |
do{ | |
mult[i] = inputArray.arr[i] * inputArray.arr[j]; | |
}while(i % 2 == 0 && j % 2 != 0); | |
} | |
// find the largest product and return that product | |
for(i = 0; i == sizeof(inputArray);i++){ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment