Fortran 上机题汇总

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

Fortran 复习题汇总program exer101_1

implicit none

realpi,r,t,s

C 说明符号常量

parameter(pi=3.1415926)

C 打开用于保存结果的文件

open(9,file='mydata.dat')

write(*,*)"请输入r和t的值:"

read*,r,t

s=t/360.0*pi*r**2

C 在屏幕上显示结果

print*,'r=',r,'t=',t,'s=',s

C 采用格式说明语句显示结果

write(*,100)'r=',r,'t=',t,'s=',s

100 format(1X,3(A2,F10.5,1X))

C 将结果保存至文件中

write(9,*)'r=',r,'t=',t,'s=',s

end

program exer101_2

implicit none

realpi.r,t,s

parameter(pi=3.1415926) !说明符号常量

open(9,file='mydata.dat') !打开用于保存结果的文件write(*,*)"请输入r和t的值:"

read*,r,t

s=t/360.0*pi*r**2

print*,'r=',r,'t=',t,'s=',s !在屏幕上显示结果

write(*,100)'r=',r,'t=',t,'s=',s !采用格式说明语句显示结果100 format(1X,3(A2,F10.5,1X))

write(9,*)'r=',r,'t=',t,'s=',s !将结果保存至文件中

end

1

2

program ex202 implicit none real F,C

print*,"请输入一个华氏温度:"

read*,F

C=(F-32)*5/9

print*,"摄氏温度为:",C

end

program ex203

implicit none

reala,b,x,y

print*,"请依次输入a,b,x的值" read*,a,b,x

y=(exp(a*x)+log(x)**2)/(5.0*b) print*,y

end program ex204

implicit none

real v0,t,g,s

parameter(g=9.81)

print*,"请输入v0,t的值" read*,v0,t

s=0.5*g*t**2+t*(v0)

print*,s

end

program ex301

implicit none

real I1,I2,I3,s

print*,"请输入三个整数" read*,I1,I2,I3

s=I1+I2+I3

print*,"三个整数之和为:",s print*,"第一种排列次序:

",I1,I2,I3

3

print*,"第二种排列次序:",I1,I3,I2 print*,"第三种排列次序:",I2,I1,I3 print*,"第四种排列次序:",I2,I3,I1 print*,"第五种排列次序:",I3,I1,I2 print*,"第六种排列次序:",I3,I2,I1 end

!计算三数之和,求三数排列次序program ex301_2

!说明部分开始

implicit none

integer(1)::I,J,K

integer S

print*,'请输入三个整数:'

read*,I,J,K

S=I+J+K

print*,'I1+I2+I3=',S

print*,'三个整数所有可能排列次序有:' print*,I,J,K

print*,I,K,J

print*,J,I,K

print*,J,K,I

print*,K,I,J

print*,K,J,I

end program

program ex302

implicit none

complex::c1=(3.5,4.8),c2=(7.5,-3.2) complexa,b,c,d

a=c1+c2

b=c1-c2

c=c1*c2

d=c1/c2

print*,"两数之和为:",a

print*,"两数之差为:",b

print*,"两数之积为:",c

print*,"两数之商为:",d

end

4

program ex401_1

implicit none

real A1,A2,B1,B2,C1,C2,X,Y,T A1=2.0

A2=-6.0

B1=1.0

B2=-1.0

C1=4.0

C2=4.00

T=A1*B2-A2*B1

X=(B2*C1-B1*C2)

Y=(A1*C2-A2*C1)

WRITE(*,*)'X=',X,'Y=',Y

END program ex0402

implicit none

real A1,A2,B1,B2,C1,C2,X,Y,T

write(*,*)'请输入A1,A2,,B1,B2,C1,C2的值:' read*,A1,A2,B1,B2,C1,C2

T=A1*B2-A2*B1

X=(B2*C1-B1*C2)

Y=(A1*C2-A2*C1)

WRITE(*,*)'X=',X,'Y=',Y

END

PROGRAM ex402

IMPLICIT NONE

REAL A

INTEGER I

REAL R

WRITE(*,*)'ENTER REAL A(A>0):'

5

相关文档
最新文档