Skip to content

Instantly share code, notes, and snippets.

@uhfx uhfx/prog3-3_.c
Created Dec 5, 2017

Embed
What would you like to do?
#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
You can’t perform that action at this time.