第三章
二、将数学式写成fortran表达式 (1)a**2+4*b**3)/(a-b)
(2)(-b+sqrt(b*b-4*a*c))/(2*a) (3)(6*sin((x+y)**2))/(2*a) (4)sin(y/(aqrt(x*x+y*y)))
(5)sin(atan(aqrt(x*x+y*y))/(abs(c))) 九、电路编程
Implicit real(a-z) R1=30 R2=60 R3=45 U=120
I=(u/r1+u/r2+u/r3) Print*,i End
结果:8.666667
十、六边形面积编程 ! main program
Implicit real(a-z) I1=10 I2=20 I3=16 I4=13 I5=21 I6=14 I7=30 I8=36 I9=28
Area=x(i2,i3,i7)+x(i1,i7,i8)+X(i4,i8,i9)+x(i5,i6,i9) Print*,'area=',area End
! function program
Function X(a1,a2,a3) B=(a1+a2+a3)/2
X=sqrt(b*(b-a1)*(b-a2)*(b-a3)) End
结果:area=581.2570
十一、分期付款编程 read(*,*)d,p,r
m=(log(p)-log(p-d*r))/log(1+r) m=m+1 print*,m end
十二、借贷款编程 ! daikuan real i read(*,*)a,r,n i=r+1 d=(a*(i**n-1))/((i-1)*i**n) d=int(d*10+0.5)/10 print*,d End
第四章
四、税款编程 ! calculate Tax real income,tax read(*,*)income if(income.le.400)then tax=0 else tax=(income-400)*0.2 end if print*,'tax=',tax end
五、求y编程 ! calculate y real x,y read(*,*)x if(x.ge.0.and.x.lt.10)then y=x else if(x.ge.10.and.x.lt.20)then y=x*x+1
else if(x.ge.20.and.x.lt.30)then y=x*x*x+x*x+1 end if print*,'x=',x,'y=',y end 六、整除编程 ! zhengchu read(*,*)m if(mod(m,7).eq.0)print*,m,'能被7整除' if(mod(m,11).eq.0)print*,m,'能被11整除'
if(mod(m,17).eq.0)print*,m,'能被17整除' if(mod(m,7).ne.0.and.mod(m,11).ne.0.and.mod(m,17).ne.0)print*,m,'不能被7,11,17整除'
end
八、大小排序编程 ! program
read(*,*)a,b,c,d if(a.lt.b) then temp=a a=b b=temp end if if(a.lt.c) then temp=a a=c c=temp end if
if(a.lt.d) then temp=a a=d d=temp end if
if(b.lt.c) then temp=b b=c c=temp end if if(b.lt.d) then temp=b b=d d=temp end if if(c.lt.d) then temp=c c=d d=temp end if print*,a,b,c,d end
九、高程编程 ! program read(*,*)x,y if((x-2)**2+(y-2)**2.le.1) then
h=10 else if((x+2)**2+(y+2)**2.le.1) then h=10 else if((x-2)**2+(y+2)**2.le.1) then h=10 else if((x+2)**2+(y-2)**2.le.1) then h=10 else h=0 end if print*,'H=',h end
十、建筑规划编程 ! program read(*,*)x,y if(abs(x).le.10.and.abs(y).le.10) then h=20 else if(abs(x).le.20.and.abs(y).le.20) then h=30
else if(abs(x).le.30.and.abs(y).le.30) then h=50 else h=100 end if print*,'h=',h end 一、 求和编程 ! program sum=0 sign=1 do 100,i=1,100,1 sum=sum+sign*1.0/i sign=sign*(-1) 100 continue
print*,'sum=',sum end
结果为:0.6881718 二、 求和编程 ! program sum=0 do 100 ,i=1,20,1
第五章
sum=sum+1.0/i/(i+1) 100 continue
print*,'sum=',sum end
结果为:0.9900995 四、 sinx函数编程 ! program sum=0 read(*,*)x temp=x sign=1 i=1 do 100,while(abs(temp).gt.1e-10) sum=sum+sign*temp sign=sign*(-1) i=i+2 temp=temp*x*x/i/(i-1) 100 continue print*,sum end
五、 电阻编程 ! program read(*,*) R0,R1,R2 temp=R0 do 100,i=1,3,1 temp=(temp+r1)*R2/(temp+R1+R2) 100 continue
print*,temp end
七、 分解因子编程 ! program read(*,*) m print*,m,'=1' 20 continue
do 100,i=2,m,1 if(mod(m,i).eq.0) then print*,'*',i m=m/i goto 20 end if 100 continue