b=1. a=0. n=1000 dx=(b-a)/n sum=0. do i=1,n-1 x=a+i*dx+dx/2. sum=sum+f(x)*dx enddo print*,sum stop end function f(x) f=x**2 return end real,allocatable:: a(:,:),b(:,:),c(:,:) open(10,file="test_3.in") read (10,*) n allocate (a(n,n),b(n,n),c(n,n)) read (10,*)a ,b do i=1,n do j=1,n sum=0. do k=1,n sum=sum+a(i,k)*b(k,j) enddo c(i,j)=sum enddo enddo do i=1,n print '(100f10.5)',c(i,:) enddo stop end real,allocatable:: a(:) open(10,file="test_4.in") read (10,*)n allocate(a(n)) read(10,*)a amax=-1.e32 amin= 1.e32 do i=1,n if(a(i).gt.amax)then amax=a(i) endif if(a(i).lt.amax)then amin=a(i) endif enddo print *,amin,amax stop end b=1. fb=f(b) n=10000000 ns=0 do i=1,n xj=rand(0)*b yj=rand(0)*fb y=f(xj) if(y.ge.yj)then ns=ns+1 endif enddo print *,ns*b*fb/n stop end function f(x) f=x*x return end n=10000000 ns=0 do i=1,n xj=rand(0) yj=rand(0) if(yj**2+xj**2.le.1.)then ns=ns+1 endif enddo print *,ns*4./n stop end function f(x) f=x*x return end pi=3.1415926536 print *," x[rad] x[grad] sin cos tan" print *,"============================================================" do x=0.,pi/2.,0.01 print '(5f12.4)',x,x*180/pi,sin(x),cos(x),tan(x) enddo stop end real,allocatable::a(:) open(10,file="test1.in") read (10,*) n allocate(a(n)) read(10,*)a sum=0. do i=1,n sum=sum+a(i) enddo print *,sum stop end external func a=0. b=1. abserr=0.0000 relerr=0.0000001 call quanc8(func,a,b,abserr,relerr,result,errest,nofun,flag) print *,result*4.,errest stop end function func(x) func=sqrt(abs(1.-x*x)) return end read *,n nr=0 do i=1,n x=rand() y=rand() if ((x*x+y*y).le.1)then nr=nr+1 endif enddo print*,4.*nr/n stop end call srand(23) do i=1,10 print *, rand() enddo stop end