Fortran95习题答案.doc
《Fortran95习题答案.doc》由会员分享,可在线阅读,更多相关《Fortran95习题答案.doc(130页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateFortran95习题答案第四章第四章1.program main implicit none write(*,*) Have a good time. write(*,*) Thats not bad. write(*,*) Mary isnt my name.end program2.program main real, parameter : PI=3 impl
2、icit none.14159 real radius write(*,*) 请输入半径长 read(*,*) radius write(*,( 面积=f8. 3) radius*radius*PIend program3.program main implicit none real grades write(*,*) 请输入成绩 read(*,*) grades write(*,( 调整后成绩为 f8.3) SQRT(grades)*10.0end program4.integer a,breal ra,rba=2b=3ra=2.0rb=3.0write(*,*) b/a ! 输出1, 因
3、为使用整数计算, 小数部分会无条件舍去write(*,*) rb/ra ! 输出1.55.program main implicit none type distance real meter, inch, cm end type type(distance) : d write(*,*) 请输入长度: read(*,*) d%meter d%cm = d%meter*100 d%inch = d%cm/2.54 write(*,(f8.3米 =f8.3厘米 =f8.3英寸) d%meter, d%cm, d%inchend program第五章1.program main implicit
4、none integer money real tax write(*,*) 请输入月收入 read(*,*) money if ( money1000 ) then tax = 0.03 else if ( money5000) then tax = 0.1 else tax = 0.15 end if write(*,( 税金为 I8) nint(money*tax)end program2.program main implicit none integer day character(len=20) : tv write(*,*) 请输入星期几 read(*,*) day select
5、 case(day) case(1,4) tv = 新闻 case(2,5) tv = 电视剧 case(3,6) tv = 卡通 case(7) tv = 电影 case default write(*,*) 错误的输入stop end select write(*,*) tvend program3.program main implicit none integer age, money real tax write(*,*) 请输入年龄 read(*,*) age write(*,*) 请输入月收入 read(*,*) money if ( age50 ) then if ( mone
6、y1000 ) then tax = 0.03else if ( money5000 )then tax = 0.10else tax = 0.15end if else if ( money1000 ) then tax = 0.5else if ( money5000 )then tax = 0.7else tax = 0.10end if end if write(*,( 税金为 I8) nint(money*tax)end program4.program main implicit none integer year, days logical mod_4, mod_100, mod
7、_400 write(*,*) 请输入年份 read(*,*) year mod_4 = ( MOD(year,4) = 0 ) mod_100 = ( MOD(year,100) = 0 ) mod_400 = ( MOD(year,400) = 0 ) if ( (mod_4 .NEQV. mod_100) .or. mod_400 ) then days = 366 else days = 365 end if write(*,(这一年有I3天) days stopend program第六章1.program main implicit none integer i do i=1,5
8、write(*,*) Fortran end do stopend program2.program main implicit none integer i,sum sum = 0 do i=1,99,2 sum = sum+i end do write(*,*) sum stopend program3.program main implicit none integer, parameter : answer = 45 integer, parameter : max = 5 integer weight, i do i=1,max write(*,*) 请输入体重read(*,*) w
9、eightif ( weight=answer ) exit end do if ( i=max ) then write(*,*) 猜对了 else write(*,*) 猜错了 end if stopend program4.program main implicit none integer, parameter : max=10 integer i real item real ans ans = 1.0 item = 1.0 do i=2,max item = item/real(i) ans = ans+item end do write(*,*) ans stopend prog
10、ram5.program main implicit none integer, parameter : length = 79 character(len=length) : input, output integer i,j write(*,*) 请输入一个字串 read(*,(A79) input j=1 do i=1, len_trim(input) if ( input(i:i) /= ) then output(j:j)=input(i:i) j=j+1end if end do write(*,(A79) output stopend program第七章1.program ma
11、in implicit none integer, parameter : max = 10 integer i integer : a(max) = (/ (2*i, i=1,10) /) integer : t ! sum()是fortran库函数 write(*,*) real(sum(a)/real(max) stopend program2.integer a(5,5) ! 5*5=25integer b(2,3,4) ! 2*3*4=24integer c(3,4,5,6) ! 3*4*5*6=360integer d(-5:5) ! 11integer e(-3:3, -3:3)
12、 ! 7*7=493.program main implicit none integer, parameter : max=10 integer f(max) integer i f(1)=0 f(2)=1 do i=3,max f(i)=f(i-1)+f(i-2) end do write(*,(10I4) f stopend program4.program mainimplicit none integer, parameter : size=10 integer : a(size) = (/ 5,3,6,4,8,7,1,9,2,10 /) integer : i,j integer
13、: t do i=1, size-1 do j=i+1, size if ( a(i) a(j) ) then ! a(i)跟a(j)交换 t=a(i) a(i)=a(j)a(j)=t end ifend do end do write(*,(10I4) a stopend5.a(2,2) ! 1+(2-1)+(2-1)*(5) = 7a(3,3) ! 1+(3-1)+(3-1)*(5) = 13第八章1.program main implicit none real radius, area write(*,*) 请输入半径长 read(*,*) radius call CircleArea
14、(radius, area) write(*,( 面积 = F8.3) area stopend programsubroutine CircleArea(radius, area) implicit none real, parameter : PI=3.14159 real radius, area area = radius*radius*PI returnend subroutine2.program main implicit none real radius real, external : CircleArea write(*,*) 请输入半径长 read(*,*) radius
15、 write(*,( 面积 = F8.3) CircleArea(radius) stopend programreal function CircleArea(radius) implicit none real, parameter : PI=3.14159 real radius CircleArea = radius*radius*PI returnend function3.program main implicit none call bar(3) call bar(10) stopend programsubroutine bar(length) implicit none in
16、teger, intent(in) : length integer i character(len=79) : string string= do i=1,length string(i:i)=* end do write(*,(A79) string returnend subroutine4.program main implicit none integer, external : add write(*,*) add(100)end programrecursive integer function add(n) result(sum) implicit none integer,
17、intent(in) : n if ( n0 ) then sum=0return else if ( n=1 ) then sum=nreturn end if sum = n + add(n-1) returnend function5.program main implicit none integer, external : gcd write(*,*) gcd(18,12)end programinteger function gcd(A,B) implicit none integer A,B,BIG,SMALL,TEMP BIG=max(A,B) SMALL=min(A,B) d
18、o while( SMALL /= 1 ) TEMP=mod(BIG,SMALL) if ( TEMP=0 ) exit BIG=SMALL SMALL=TEMP end do gcd=SMALL returnend function6.program main use TextGraphLib implicit none integer, parameter : maxx=60, maxy=20 real, parameter : StartX=0.0, EndX=3.14159*2.0 real, parameter : xinc = (EndX-StartX)/(maxx-1) real
19、 x integer i,px,py call SetScreen(60,20) call SetCurrentChar(*) x=StartX do px=1,maxx py = (maxy/2)*sin(x)+maxy/2+1 call PutChar(px,py)x=x+xinc end do call UpdateScreen() stopend program第九章1.program main implicit none character(len=79) : filename character(len=79) : buffer integer, parameter : filei
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Fortran95 习题 答案
限制150内