Skip to content

Instantly share code, notes, and snippets.

@wufe
Created September 16, 2018 21:20
Show Gist options
  • Save wufe/f5343399cdaac7c6ddd7a6acec722420 to your computer and use it in GitHub Desktop.
Save wufe/f5343399cdaac7c6ddd7a6acec722420 to your computer and use it in GitHub Desktop.
asd
#include <stdio.h>
#include <math.h>
int main() {
int array[7] = {1,1,1,2,1,1,1};
int arrayLength = sizeof(array)/sizeof(int);
printf("Array length is %d\n", arrayLength);
double mid = (double)arrayLength / 2;
int pivotIndex = ceil(mid);
printf("The pivotal index is %d\n", pivotIndex);
int isNegativeInfinity = 1;
int maxSum = 0;
for (int i = 0; i < pivotIndex; i++) {
int leftIndex = i;
int rightIndex = arrayLength - 1 - i;
int leftNumber = array[leftIndex];
int rightNumber = array[rightIndex];
printf("Summing number at index %d (%d) with number at index %d (%d)\n", leftIndex, leftNumber, rightIndex, rightNumber);
int sum = leftNumber + rightNumber;
printf("The sum is %d\n", sum);
if (isNegativeInfinity == 1 || (sum > maxSum)) {
printf("and is higher than previous one (%d)\n", maxSum);
maxSum = sum;
isNegativeInfinity = 0;
}
}
printf("The maximum sum is %d", maxSum);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment