当前位置:首页 > FORTRAN程序设计复习题及答案
程序运行结果是: 0.00
3、阅读下列FORTRAN程序: program example implicit none
integer rain, windspeed write(*,*) \ read(*,*) rain write(*,*) \ read(*,*) windspeed
If ( rain>=500 .or. windspeed >=10 ) then write(*,*) \停止上班上课\ else
write(*,*) \照常上班上课\ end if stop end
运行上述程序时,如果从键盘输入 Rain:
505<回车> Wind:
8<回车>
则最后输出的结果为: 停止上班上课
4、阅读下列FORTRAN程序: program example implicit none real a,b,ans
character operator read(*,*) a
read(*,\ read(*,*) b
select case(operator) case('+') ans = a+b case('-') ans = a-b case('*') ans = a*b case('/') ans = a/b case default
write(*,\ stop
end select
write(*,\ stop end
运行上述程序时,如果从键盘输入 100<回车> ?<回车> 200<回车>
则最后输出的结果为: Unknown operator ? 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
共分享92篇相关文档