Skip to content

Instantly share code, notes, and snippets.

@Villelmo
Last active March 15, 2018 00:36
Show Gist options
  • Save Villelmo/adcf4f5e232868d47294f82e2ec933a4 to your computer and use it in GitHub Desktop.
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.
// 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