100财富值求fortran95程序!具体是从0到1000之间随机选出两个素数(也有叫质数的)p和
100财富值求fortran95程序!具体是从0到1000之间随机选出两个素数(也有叫质数的)p和q,且p大于q的程序,求大神们帮帮我啊...
100财富值求fortran95程序!具体是从0到1000之间随机选出两个素数(也有叫质数的)p和q,且p大于q的程序,求大神们帮帮我啊
展开
1个回答
展开全部
生成一个数组,然后随机数组编号就好了
program baidu
integer::I,J,K,N
logical::f
integer,dimension(500)::re
real::x1,x2,x3
integer::ra,rb,p,q
N=2
re(1)=2
do I=2,1000
K=float(I)**0.5+1
f=.true.
do J=2,K
if (mod(I,J)==0 ) then
f=.false.
goto 10
endif
enddo
10 if(f)then
re(N)=I
N=N+1
endif
enddo
N=N-1
call random_seed()
do
call random_number(x1)
if (x1*n>=2.0) exit
enddo
do
call random_number(x2)
if (x2*n>=2.0) exit
enddo
if (x1>x2)then
x3=x1
x1=x2
x2=x3
endif
ra=x1*n
rb=x2*n
P=re(rb)
Q=re(ra)
write(*,*)"P:",P,"Q:",Q
pause
end
program baidu
integer::I,J,K,N
logical::f
integer,dimension(500)::re
real::x1,x2,x3
integer::ra,rb,p,q
N=2
re(1)=2
do I=2,1000
K=float(I)**0.5+1
f=.true.
do J=2,K
if (mod(I,J)==0 ) then
f=.false.
goto 10
endif
enddo
10 if(f)then
re(N)=I
N=N+1
endif
enddo
N=N-1
call random_seed()
do
call random_number(x1)
if (x1*n>=2.0) exit
enddo
do
call random_number(x2)
if (x2*n>=2.0) exit
enddo
if (x1>x2)then
x3=x1
x1=x2
x2=x3
endif
ra=x1*n
rb=x2*n
P=re(rb)
Q=re(ra)
write(*,*)"P:",P,"Q:",Q
pause
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询