fortran课后习题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

f(0)=0 f(1)=1 write(*,*) f(0) write(*,*) f(1) do n=2,9 f(n)=f(n-1)+f(n-2) write(*,*) f(n) end do end 7.4 program main implicit none integer::a(10)=(/5,3,6,4,8,7,1,9,2,10/) integer::i,j integer t do i=1,9 do j=i+1,10 if(a(i)<a(j)) then t=a(i) a(i)=a(j) a(j)=t end if end do end do write(*,"(10I4)") A end
Байду номын сангаас
write(*,*)"一年有366天" else if(mod(day,100)==0.and.mod(day,400)==0) then write(*,*)"一年有366天" else write(*,*)"一年有365天" end if End 6.1 method one: program main implicit none integer counter do counter=1,5 write(*,*)"Fortran" end do end method two: program main implicit none integer counter counter=1 do while(counter<=5) write(*,*)"Fortran" counter=counter+1 end do end 6.2 program main implicit none integer counter integer::ans=0 counter=1 do while(counter<100) ans=ans+counter counter=counter+2 end do
4.1 program main implicit none write(*,*) "Have a good time." write(*,*) "that's not bad." write(*,*) """Mary"" isn't my name." end 4.2 program main implicit none real::pi=3.14 real::s integer r read(*,*) r s=pi*r**2 write(*,*) s end 4.3 program main implicit none real grades real g write(*,*) "请输入成绩" read(*,*) grades g=grades**0.5*10 write(*,*) "调整后的成绩为" write(*,*)g end 4.5 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%inch
7.1 program main implicit none integer::a(10) integer i,sum real b sum=0 do i=1,10 a(i)=2*i sum=sum+a(i) write(*,*) a(i) end do b=sum/10 write(*,*) "10个数字的平均值为:" write(*,*) b end 7.3 program main implicit none integer::f(0:9) integer n
5.1 program main implicit none integer shouru real suijin read(*,*) shouru if (shouru>0 .and.shouru<1000) then suijin=shouru*0.03 else if (shouru>=1000 .and. shouru<=5000) then suijin=shouru*0.1 else if (shouru>5000) then suijin=shouru*0.15 end if write(*,*)"应缴纳的税金金额为:" write(*,*) suijin end 5.2 program main implicit none character(10) day character(10)jiemu read(*,*) day select case(day) case('monday','thursday') jiemu="新闻" case('tuesday','friday') jiemu="电视剧" case('wendesday','staurday') jiemu="卡通片" case('sunday') jiemu="电影" case default write(*,*)"输入错误" end select write(*,*) jiemu end
write(*,*)ans end 6.3 method one: program ex0605 implicit none integer counter real,parameter::weight=45.0 real,parameter::e=0.001 real::guess=0.0 do counter=1,5 write(*,*)"weight:" read(*,*) guess if (abs(guess-weight)<e) then write(*,*)"you're right" exit else write(*,*)"you're wrong" end if end do end 6. 4 program main implicit none integer a real ::b=1 real::sum=0 real c write(*,*)"以循环来计算1/1!+1/2!+1/3!+...1/10!的值:" do a=1,10 b=b*a c=1/b sum=sum+c end do write(*,*) sum End 6.5 program main implicit none
5.3 program main implicit none integer nian,shouru real suijin read(*,*) nian read(*,*) shouru if (nian<50.and.nian>0) then if (shouru>=1000 .and. shouru<=5000) then suijin=shouru*0.1 end if if (shouru>5000) then suijin=shouru*0.15 end if if (shouru<1000) then suijin=shouru*0.03 end if else if (nian>50) then if (shouru>=1000 .and. shouru<=5000) then suijin=shouru*0.07 end if if (shouru>5000) then suijin=shouru*0.1 end if if (shouru<1000) then suijin=shouru*0.05 end if end if write(*,*)"应缴纳的税金金额为:" write(*,*) suijin end 5.4 program main implicit none integer day write(*,*) "请输入一个公元的年份:" read(*,*) day if (mod(day,4)==0) then
integer i,n,l character(20) s,m write(*,*) "输入字符串:" read (*,"(A20)") s i=len_trim(s) l=1 do n=1,i if (s(n:n)/='') then m(l:l)=s(n:n) l=l+1 end if end do write(*,"(A20)") m End
相关文档
最新文档