Skip to content

Instantly share code, notes, and snippets.

@uhfx
Created December 5, 2017 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhfx/d42cac39fe092df2ee99f19a45b7ca2c to your computer and use it in GitHub Desktop.
Save uhfx/d42cac39fe092df2ee99f19a45b7ca2c to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
int main(void)
{
double x, y, z, z_max, x_max, y_max;
srand((unsigned int) time(NULL));
int i;
z_max=0; x_max=0; y_max=0;
for(i=0; i<1000000; i++) {
x = ((double)rand() / RAND_MAX)*9+1;
y = ((double)rand() / RAND_MAX)*9+1;
z = x*(10+31*pow(x, -0.5)+1.3*pow(y, -0.2))-18*x
+y*(5+15*pow(y, -0.4)+0.8*pow(x, -0.08))-10*y;
/* printf("x = %f, y = %f, z = %f\n", x, y, z); */
if (z >z_max){
x_max = x;
y_max = y;
z_max = z;
}
}
printf("x_max = %f, y_max = %f, z_max = %f\n", x_max, y_max, z_max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment