Fortran复习题(2)

2019-08-29 00:10

5、阅读下列FORTRAN程序: program example implicit none integer i

integer strlen

integer, parameter :: key = 2 character(len=20) :: string write(*,*) \ read(*,*) string

strlen = len_trim(string) do i = 1, strlen

string(i:i) = char( ichar(string(i:i)) + key ) end do

write(*,\ stop end

BCDIJK<回车>

则最后输出的结果为: DEFKLM

6、阅读下列FORTRAN程序: program example implicit none integer i,j do i=1, 2

do j=2, 3, 2

write(*, \ end do

write(*,*) \ end do stop end

程序运行的结果是: 1 2

another circle 2 2 another circle

(按输出格式,1、2前均有一空格。若题目无特殊说明,不需表达出;若有说明,则空格用“□”表示)

7、阅读下列FORTRAN程序: program example implicit none

integer :: dest = 6 integer floor do floor=1, dest

if ( floor==2 .or. floor==4 ) cycle write(*,*) floor end do stop end

程序运行的结果是: 1

3 5 6

8、阅读下列FORTRAN77程序: program example

implicit none

integer, parameter :: limit=10 integer counter integer :: ans = 0 counter = 1

do while( counter <= limit ) ans = ans + counter counter = counter + 2 end do

write(*,*) ans stop end

程序运行的结果是: 25

9、阅读下列FORTRAN程序: program example implicit none

integer, parameter :: students = 5

integer :: student(students) = (/ 80, 90, 85, 75, 95 /) integer i

do while( .true. ) write(*,*) \ read(*,*) i

if ( i<=0 .or. i>students ) exit write(*,*) student(i) end do stop end

运行上述程序时,如果从键盘输入 3<回车>

则最后输出的结果为: 85

10、阅读下列FORTRAN程序: program example implicit none

integer, parameter :: L=2, M=3, N=2 real :: A(L,M) = (/ 1,2,3,4,5,6/) real :: B(M,N) = (/ 1,2,3,4,5,6/) real :: C(L,N) integer :: i,j,k do i=1,L do j=1,N

C(i,j) = 0.0 do k=1,M

C(i,j) = C(i,j)+A(i,k)*B(k,j) end do end do end do do i=1,L

write(*,*) C(i,:) end do stop end

程序运行的结果是: 22 49

28 64

11、阅读下列FORTRAN程序: program example implicit none

integer :: i,j loop1: do i=1,3 loop2: do j=1,3

if ( i==3 ) exit loop1 if ( j==2 ) cycle loop2

write(*, \ end do loop2 end do loop1 stop end

程序运行的结果是: (1,1) (1,3)

(2,1) (2,3)

12、阅读下列FORTRAN程序: program example implicit none real :: a=1.0

call ShowInteger(a) call ShowReal(a) stop end

subroutine ShowInteger(num) implicit none integer :: num write(*,*) num return end

subroutine ShowReal(num) implicit none real :: num write(*,*) num return end

程序运行的结果是: 随机数

1.000000

13、阅读下列FORTRAN程序: program example implicit none

integer, parameter :: row = 2 integer, parameter :: col = 2 integer :: m(row, col) integer r integer c

data ((m(r,c), r=1, 2), c=1,2) /1,2,3,4/

write(*,\ stop end

程序运行的结果是: 1 3 2 4 14、阅读下列FORTRAN程序: program ex0805 implicit none

integer :: a = 1 integer :: b = 2

write(*,*) a,b call add(a) call add(b) write(*,*) a,b stop end

subroutine add(num) implicit none integer :: num num = num+1 return end

程序运行的结果是: 1 2 2 3

15、阅读下列FORTRAN程序: program example implicit none

integer, parameter :: size=10

integer :: a(size) = (/ 5,3,6,4,8,7,1,9,2,10 /) integer :: i,j integer :: t do i=1, size-1 do j=i+1, size

if ( a(i) > a(j) ) then t=a(i) a(i)=a(j) a(j)=t end if end do end do

write(*,\ stop end

程序运行的结果是: 1 2 3 4 5 6 7 8 9 10

16、阅读下列FORTRAN程序: program example implicit none real :: a=1 real :: b=2

real, external :: add


Fortran复习题(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2014年杭州民办初中新生素质测试模拟试卷(分班考含答案)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: