Skip to content

Instantly share code, notes, and snippets.

@awave1
Created September 16, 2018 04:34
Show Gist options
  • Save awave1/1ed4809bb3510939cebf905efc2c20b5 to your computer and use it in GitHub Desktop.
Save awave1/1ed4809bb3510939cebf905efc2c20b5 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <math.h>
#define MAX_X 5
#define MIN_X -6
int f(int x) {
return (-5*pow(x, 3)) - (31 * pow(x, 2)) + (4 * x) + 31;
}
int main() {
// assume max at the max x of given range
int max = f(MAX_X);
int res;
for (int x = MIN_X; x < MAX_X + 1; x++) {
res = f(x);
if (res > max) {
max = res;
}
}
printf("MAX: %d", max);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment