版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、(完整)fortran95程序設(shè)計(jì)課后習(xí)題答案(word版方便)(完整)fortran95程序設(shè)計(jì)課后習(xí)題答案(word版方便) 編輯整理:尊敬的讀者朋友們:這里是精品文檔編輯中心,本文檔內(nèi)容是由我和我的同事精心編輯整理后發(fā)布的,發(fā)布之前我們對(duì)文中內(nèi)容進(jìn)行仔細(xì)校對(duì),但是難免會(huì)有疏漏的地方,但是任然希望((完整)fortran95程序設(shè)計(jì)課后習(xí)題答案(word版方便))的內(nèi)容能夠給您的工作和學(xué)習(xí)帶來(lái)便利。同時(shí)也真誠(chéng)的希望收到您的建議和反饋,這將是我們進(jìn)步的源泉,前進(jìn)的動(dòng)力。本文可編輯可修改,如果覺(jué)得對(duì)您有幫助請(qǐng)收藏以便隨時(shí)查閱,最后祝您生活愉快 業(yè)績(jī)進(jìn)步,以下為(完整)fortran95程序設(shè)計(jì)
2、課后習(xí)題答案(word版方便)的全部?jī)?nèi)容。第四章1。program main implicit none write(,) ”have a good time。” write(*,*) thats not bad.” write(,) ”mary” isnt my name。 end program 2.program main real, parameter : pi=3 implicit none.14159 real radius write(*,*) 請(qǐng)輸入半徑長(zhǎng)” read(*,) radius write(,( 面積=f8。 3)”) radiusradius*pi end pro
3、gram 3。program main implicit none real grades write(*,) ”請(qǐng)輸入成績(jī) read(*,) grades write(,( 調(diào)整后成績(jī)?yōu)?f8.3)”) sqrt(grades)10.0 end program 4。integer a,b real ra,rb a=2 b=3 ra=2.0 rb=3。0 write(,*) b/a ! 輸出1, 因?yàn)槭褂谜麛?shù)計(jì)算, 小數(shù)部分會(huì)無(wú)條件舍去 write(*,) rb/ra ! 輸出1.5 5。program main implicit none type distance real meter,
4、inch, cm end type type(distance) :: d write(*,) 請(qǐng)輸入長(zhǎng)度: read(,*) dmeter dcm = d%meter*100 dinch = d%cm/2。54 write(,”(f8.3米 =f8.3厘米 =f8.3英寸) dmeter, d%cm, d%inch end program 第五章1。program main implicit none integer money real tax write(,) ”請(qǐng)輸入月收入 read(*,) money if ( money1000 ) then tax = 0。03 else if
5、( money5000) then tax = 0。1 else tax = 0.15 end if write(*,( 稅金為 i8)”) nint(moneytax) end program 2。program main implicit none integer day character(len=20) : tv write(,) ”請(qǐng)輸入星期幾 read(*,*) day select case(day) case(1,4) tv = ”新聞” case(2,5) tv = ”電視劇 case(3,6) tv = ”卡通” case(7) tv = 電影” case default
6、write(*,) 錯(cuò)誤的輸入 stop end select write(*,) tv end program 3.program main implicit none integer age, money real tax write(*,*) 請(qǐng)輸入年齡 read(,) age write(,) ”請(qǐng)輸入月收入” read(*,*) money if ( age50 ) then if ( money1000 ) then tax = 0.03 else if ( money5000 )then tax = 0。10 else tax = 0.15 end if else if ( mo
7、ney1000 ) then tax = 0。5 else if ( money5000 )then tax = 0。7 else tax = 0。10 end if end if write(,”( 稅金為 i8)) nint(moneytax) end program 4。program main implicit none integer year, days logical mod_4, mod_100, mod_400 write(,*) ”請(qǐng)輸入年份 read(*,*) year mod_4 = ( mod(year,4) = 0 ) mod_100 = ( mod(year,10
8、0) = 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 stop end program 第六章1。program main implicit none integer i do i=1,5 write(*,*) ”fortran” end do stop end program 2.program main implicit none integer i,
9、sum sum = 0 do i=1,99,2 sum = sum+i end do write(*,) sum stop end program 3。program main implicit none integer, parameter :: answer = 45 integer, parameter : max = 5 integer weight, i do i=1,max write(*,*) ”請(qǐng)輸入體重” read(,*) weight if ( weight=answer ) exit end do if ( i=max ) then write(,*) 猜對(duì)了” else
10、 write(,*) 猜錯(cuò)了 end if stop end program 4.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 stop end program 5.program main implicit none integer, parameter :: length = 79 charact
11、er(len=length) :: input, output integer i,j write(,) 請(qǐng)輸入一個(gè)字串” read(,”(a79) input j=1 do i=1, len_trim(input) if ( input(i:i) /= ) then output(j:j)=input(i:i) j=j+1 end if end do write(*,(a79) output stop end program 第七章1。program main implicit none integer, parameter :: max = 10 integer i integer : a
12、(max) = (/ (2i, i=1,10) /) integer :: t ! sum()是fortran庫(kù)函數(shù) write(*,) real(sum(a)/real(max) stop end program 2。integer a(5,5) ! 55=25 integer b(2,3,4) ! 234=24 integer c(3,4,5,6) ! 3*45*6=360 integer d(5:5) ! 11 integer e(3:3, -3:3) ! 7*7=49 3.program main implicit none integer, parameter : max=10 in
13、teger f(max) integer i f(1)=0 f(2)=1 do i=3,max f(i)=f(i-1)+f(i2) end do write(,”(10i4)) f stop end program 4.program main 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 ! a(i)跟a
14、(j)交換 t=a(i) a(i)=a(j) a(j)=t end if end do end do write(,(10i4)”) a stop end 5.a(2,2) ! 1+(2-1)+(21)*(5) = 7 a(3,3) ! 1+(3-1)+(3-1)*(5) = 13 第八章1.program main implicit none real radius, area write(,) 請(qǐng)輸入半徑長(zhǎng) read(*,) radius call circlearea(radius, area) write(,”( 面積 = f8.3)) area stop end program su
15、broutine circlearea(radius, area) implicit none real, parameter :: pi=3.14159 real radius, area area = radiusradiuspi return end subroutine 2。program main implicit none real radius real, external : circlearea write(,*) 請(qǐng)輸入半徑長(zhǎng) read(,) radius write(,”( 面積 = f8。3)”) circlearea(radius) stop end program
16、real function circlearea(radius) implicit none real, parameter :: pi=3。14159 real radius circlearea = radiusradius*pi return end function 3.program main implicit none call bar(3) call bar(10) stop end program subroutine bar(length) implicit none integer, intent(in) : length integer i character(len=7
17、9) : string string= do i=1,length string(i:i)=* end do write(,”(a79)”) string return end subroutine 4.program main implicit none integer, external : add write(*,) add(100) end program recursive integer function add(n) result(sum) implicit none integer, intent(in) :: n if ( n0 ) then sum=0 return els
18、e if ( na write(,) p ! 1 p=b write(*,) p ! 2 p=c p=5 write(*,*) c ! 5 3.module linklist type student integer : num integer :: chinese, english, math, science, social end type type datalink type(student) :: item type(datalink), pointer :: next end type contains function searchlist(num, head) implicit
19、 none integer :: num type(datalink), pointer : head, p type(datalink), pointer :: searchlist p=head nullify(searchlist) do while( associated(p) ) if ( pitemnum=num ) then searchlist = p return end if p=p%next end do return end function end module linklist program ex1016 use linklist implicit none ch
20、aracter(len=20) : filename character(len=80) :: tempstr type(datalink), pointer : head type(datalink), pointer :: p type(student), allocatable : s(:) integer i,error,size write(,*) ”filename:” read(*,*) filename open(10, file=filename, status=”old, iostat=error) if ( error/=0 ) then write(,*) open f
21、ile fail!” stop end if allocate(head) nullify(headnext) p=head size=0 read(10, ”(a80) tempstr ! 讀入第一行字符串, 不需要處理它 ! 讀入每一位學(xué)生的成績(jī) do while(.true.) read(10,fmt=*, iostat=error) pitem if ( error/=0 ) exit size=size+1 allocate(pnext, stat=error) ! 新增下一個(gè)數(shù)據(jù) if ( error/=0 ) then write(,*) ”out of memory! stop
22、 end if p=p%next ! 移動(dòng)到鏈表的下一個(gè)數(shù)據(jù) nullify(p%next) end do write(*,”(總共有,i3,位學(xué)生)”) size allocate( s(size) ) p=head do i=1,size s(i)=pitem p=p%next end do do while(。true.) write(*,*) ”要查詢幾號(hào)同學(xué)的成績(jī)?” read (*,) i if ( i1 。or. isize ) exit ! 輸入不合理的座號(hào) write(,”(5(a6,i3)) 中文”,s(i)chinese, 英文”,s(i)english,& 數(shù)學(xué),s(i
23、)%math,& 自然”,s(i)science,& 社會(huì)”,s(i)%social end do write(,”(座號(hào),i3,不存在, 程序結(jié)束。)) i stop end program 4.module typedef implicit none type :: datalink integer :: i type(datalink), pointer : next end type datalink end module typedef program ex1012 use typedef implicit none type(datalink) , pointer : p, hea
24、d, next integer : i,n,err write(*,) input n: read(,*) n allocate( head ) headi=1 nullify(headnext) p=head do i=2,n allocate( p%next, stat=err ) if ( err /= 0 ) then write(*,*) out of memory! stop end if p=pnext pi=i end do nullify(p%next) p=head do while(associated(p) write(, (i5) ) p%i p=pnext end
25、do ! 釋放鏈表的存儲(chǔ)空間 p=head do while(associated(p) next = pnext deallocate(p) p=next end do stop end program 第十一章1。module utility implicit none interface area module procedure circlearea module procedure rectarea end interface contains real function circlearea(r) real, parameter :: pi=3。14159 real r circl
26、earea = rr*pi return end function real function rectarea(a,b) real a,b rectarea = a*b return end function end module program main use utility implicit none write(,*) area(1.0) write(*,) area(2.0,3。0) stop end program 2。module time_utility implicit none type :: time integer :: hour,minute,second end
27、type time interface operator(+) module procedure add_time_time end interface contains function add_time_time( a, b ) implicit none type(time) : add_time_time type(time), intent(in) : a,b integer : seconds,minutes,carry seconds=asecond+bsecond carry=seconds/60 minutes=a%minute+bminute+carry carry=min
28、utes/60 add_time_timesecond=mod(seconds,60) add_time_time%minute=mod(minutes,60) add_time_time%hour=a%hour+bhour+carry return end function add_time_time subroutine input( a ) implicit none type(time), intent(out) :: a write(,) input hours:” read (*,) a%hour write(,) ” input minutes:” read (,) a%minu
29、te write(*,) input seconds: read (,*) asecond return end subroutine input subroutine output( a ) implicit none type(time), intent(in) :: a write(, ”(i3, hours,i3, minutes,i3, seconds)” ) ahour,aminute,asecond return end subroutine output end module time_utility program main use time_utility implicit
30、 none type(time) : a,b,c call input(a) call input(b) c=a+b call output(c) stop end program main 3。module rational_utility implicit none private public :: rational, operator(+), operator(-), operator(),& operator(/), assignment(=),operator(), operator(), operator(=), operator(/=), output, input type
31、: rational integer :: num, denom end type rational interface operator(+) module procedure rat_rat_plus_rat end interface interface operator() module procedure rat_rat_minus_rat end interface interface operator() module procedure rat_rat_times_rat end interface interface operator(/) module procedure
32、rat_rat_div_rat end interface interface assignment(=) module procedure rat_eq_rat module procedure int_eq_rat module procedure real_eq_rat end interface interface operator() module procedure rat_gt_rat end interface interface operator() module procedure rat_lt_rat end interface interface operator(=)
33、 module procedure rat_compare_rat end interface interface operator(/=) module procedure rat_ne_rat end interface contains function rat_gt_rat(a,b) implicit none logical : rat_gt_rat type(rational), intent(in) : a,b real :: fa,fb fa=real(a%num)/real(adenom) fb=real(b%num)/real(bdenom) if ( fa fb ) then rat_gt_rat=。true。 else rat_gt_rat=。false。 end if return end function rat_gt_rat function rat_lt_rat(a,b) implicit none logical : rat_lt_rat type(rational), intent(in) : a,b real : fa,fb fa=real(a%num)/real(a
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年飛行試驗(yàn)地面設(shè)備項(xiàng)目發(fā)展計(jì)劃
- 2024年家具清洗用品:洗衣皂項(xiàng)目建議書(shū)
- 2023年能源大數(shù)據(jù)項(xiàng)目分析評(píng)估報(bào)告
- 2023年防靜電超凈技術(shù)產(chǎn)品項(xiàng)目評(píng)估分析報(bào)告
- 網(wǎng)店運(yùn)營(yíng)實(shí)務(wù)學(xué)習(xí)通超星期末考試答案章節(jié)答案2024年
- 2024年羥丙基甲基纖維素項(xiàng)目發(fā)展計(jì)劃
- 2024年微型核反應(yīng)堆及配套產(chǎn)品項(xiàng)目發(fā)展計(jì)劃
- 2024年高分子合成材料項(xiàng)目合作計(jì)劃書(shū)
- 2024年超高分子量聚乙烯項(xiàng)目合作計(jì)劃書(shū)
- 2024年碳纖維針刺預(yù)制件項(xiàng)目建議書(shū)
- 2024秋四年級(jí)英語(yǔ)上冊(cè) Unit 5 Dinners ready第2課時(shí)(Let's learn Lets play)教案 人教PEP
- 2024年計(jì)算機(jī)二級(jí)WPS考試題庫(kù)380題(含答案)
- 北師大版(2019)必修第一冊(cè)Unit 1 Life Choices 大單元教學(xué)設(shè)計(jì)
- 客觀題法律職業(yè)資格考試(試卷一)試題及解答參考(2024年)
- 部編版五年級(jí)道德與法治上冊(cè)第6課《我們神圣的國(guó)土》精美課件
- (教學(xué)設(shè)計(jì))第3章 第3節(jié) 測(cè)量金屬絲的電阻率2023-2024學(xué)年新教材高中物理必修第三冊(cè)(粵教版2019)
- 國(guó)家電力投資集團(tuán)有限公司招聘筆試題庫(kù)2024
- 22G101三維彩色立體圖集
- 小學(xué)科學(xué)蘇教版六年級(jí)上冊(cè)全冊(cè)教案(2023秋新課標(biāo)版)
- 愛(ài)國(guó)知識(shí)競(jìng)賽考試題庫(kù)500題(供參考)
- 駕駛員績(jī)效考核表
評(píng)論
0/150
提交評(píng)論