Created
September 16, 2018 04:34
-
-
Save awave1/1ed4809bb3510939cebf905efc2c20b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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