用fortran语言或c语言编写的源程序,fortran语言编写一个小程序

program randomEG

implicit none

integer :: k, i,j, temp, n=10000

real :: r

integer, dimension(8) :: values

! Declare an assumed shape, dynamic array

integer, dimension(:), allocatable :: seed

integer, dimension(:), allocatable :: results

! gfortran subroutine to return date and time information

! from the real time system clock. Works down to milliseconds

! and stores the eight return values in array values.

call date_and_time(VALUES=values)

! restart the state of the pseudorandom number generator

! k = minimum size of seed (12 on my system)

call random_seed(size=k)

! allocate memory to seed

allocate(seed(k))

allocate(results(n))

! assign information in values to seed

seed(:) = values(:)

! seed the random number generator

call random_seed(put=seed)

do i=1,n

results(i) = irand()

end do

do i=1,n

do j=i+1,n

if (results(i) > results(j)) then

temp = results(i)

results(i) = results(j)

results(j) = temp

endif

enddo

enddo

do i=1,n

print *, results(i)

end do

end program randomEG

温馨提示:答案为网友推荐,仅供参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值