Compile in vs2008 SP1
Http://topic.csdn.net/u/20120312/13/a979f330-ff73-4e5d-ae92-d463c93de5bf.html? Seed = 498140863 & R = 77861318 # r_77861318
# Include <iostream>
# Include <stdio. h>
# Include <math. h>
# Include <stdlib. h>
# Include <malloc. h> // malloc () needed <stdlib. h> and <malloc. h>
Using namespace STD;
Double rnd1 (double * r)
{
Int m;
Double S, U, V, P;
S = 65536.0; u = 2053.0; V = 13849.0;
M = (INT) (* R/S); * r = * r-m * s;
* R = u * (* r) + V;
M = (INT) (* R/S );
* R = * r-m * s;
P = * R/S;
Return (P );
}
Double mtml (int n, double A [], double B [], double (* f) (INT, double *))
{
Int m, I;
Double R, S, D, * X;
// In a c ++ file, explicitly cast malloc's return.
X = (double *) malloc (N * sizeof (double ));
r = 1.0; D = 10000.0; S = 0.0;
for (m = 0; m <= 9999; m ++)
{
for (I = 0; I <= n-1; I ++)
X [I] = A [I] + (B [I]-A [I]) * rnd1 (& R );
S = S + (* f) (n, x)/d;
}< br> for (I = 0; I <= n-1; I ++)
S = S * (B [I]-A [I]);
free (x);
return (s );
}
Double mtmlf (int n, double X [])
{
Int I;
Double F;
F = 0.0;
For (I = 0; I <= n-1; I ++)
F = F + X [I] * X [I];
Return (f );
}
Void main ()
{
Static double A [3] = {1.0, 1.0, 1.0 };
Static Double B [3] = {2.0, 2.0, 2.0 };
Double mtmlf (INT, double []);
Printf ("\ n ");
Printf ("s = % E \ n", mtml (3, a, B, mtmlf ));
Printf ("\ n ");
STD: cin. Get ();
}