##Hej,##
zacząłem robić sobie zadanka na CodeFights, żeby przypomnieć sobie trochę jezyka C. To zadanie w C++ jest banalne
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
Example:
For inputArray = [3, 6, -2, -5, 7, 3], the output should be
adjacentElementsProduct(inputArray) = 21.
7 and 3 produce the largest product.
##Mój kod:##
// Definition for arrays:
// typedef struct arr_##name {
// int size;
// type *arr;
// } arr_##name;
//
// 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 maxPair;
maxPair = inputArray[0] * inputArray[1];
for(int i = 1; i < inputArray.size-1; i++){
int newPair = inputArray[i]*inputArray[i+1];
if(newPair > maxPair)
maxPair = newPair;
}
return maxPair;
}
##Moje pytanie:
Jak dobrać się do wartości , które są w tablicy? Bo za pomocą wskaźników wyskakuje taki błąd:
file.c on line 15:25: error: subscripted value is neither array nor pointer nor vector
maxPair = inputArray[0] * inputArray[1];
^