subroutine mcarlo(n,a,b,x,f,m,res,eps)
dimension a(n),b(n),x(n); external f

print *,'mcarlo: m=\t',m
sum=0; sum2=0
do k=1,m
	do i=1,n; x(i)=a(i)+rand()*(b(i)-a(i)); end do
	ff=f(n,x)
	sum=sum+ff
	sum2=sum2+ff**2
end do
vol=1; do i=1,n; vol=vol*(b(i)-a(i)); end do
print *,'mcarlo: vol=\t',vol
avg=sum/m
print *,'mcarlo: avg=\t',avg
var=sum2/m-avg**2
res=vol*avg
eps=vol*sqrt(var/m)
return
end
