已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
例1、 输入M个实数,将其相加,并输出其和。PROGRAM example_1Implicit noneInteger :n,mReal :t=0,a=0Read *,mDo Read *, a T=t+aN=n+1If (n=m) exitEnd doPrint*,tEnd program example_1例2、 求I!的阶乘(I=4,8)。Function factor(n) result(fac_result) Implicit none Integer ,intent(in):n Integer,intent(out):fac_result Integer:I Fac_result=1 Do I=1,nFac_result=fac_result*I End doEnd function factorProgram example_2 Implicit none Integer :factor,s=0,I Do I=4,8 S=s+factor(i) End doPrint*,sEnd program example_2例3、 输入一个数,判断他是否能被3整除,并输出相应的信息。Program judge Implicit none Integer : n,m Read*,n M=mod(n,3) Select case(m) IF (M= =0) THEN Case (0) Print*,yesPrint*,YES Case default ELSE Print*,noPrint*,NO End selectEND IF End program judge 例4、 判断一个整数N是否为素数PROGRAM prime Implicit none Integer :n,I,m Read*,n M= sqrt(real(n) Do I=2,mIf(mod(n,i)= =0) exit End do If (Im) thenPrint*,yes ElsePrint*,no end ifend program prime例5、 求N的阶乘PROGRAM example_5Implicit noneInteger:n,I=0,fac=1Read*,nDo while (I7) I=I+1 Fac=fac*IEnd doEnd program example_5例6、 求出全部的水仙花数。(水仙花数是个三位数,其各位数字的立方和等于该数。)program example_6 implicit none integer :I,j,k,m,n ii: do I=1,9 jj: do j=1,9 kk: do k=1,9 m=I*100+j*10+k n=I*3+j*3+k*3 if (m= =n) print*,m end do kk end do jj end do iiend program exaple_6例7、 牛顿迭代法求方程X*4+4*X+1=0的根program example_7 implicit none integer :I=1,mreal:x0,x,eread*,x0,e,m (m控制迭代次数)do x=(-x0*x0-1)/4 if (abs(x-x0)=m) then Print*,not Exit End if End do If (I max_result) max_result=b if (c max_result) max_result=c end function max3program example_11 use Exam_module real :aver3,max3 read*,a,b,c print*,aver3(),max3()end program example_11注意:(1)USE 模块名,ONLY :实体名例: use exam_module,only:a,b,此时C不再是共享变量,故C仍需通过虚实结合。 (2)use exam_module ,x-a 将模块中A与程序单元中变量X共享。例12、 递归recursive function fac(n) result(fac_result) implicit none Integer ,intent(in):n Integer,intent(out):fac_result If (n= =0) thenFac_result=1 Else Fac_result=fac(n-1)*n End ifEnd function facProgram example_12 Implicit none Interface Recursive function fac(n) result(fac_result) Integer ,intent(in):n Integer,intent(out):fac_resultEnd function facEnd interfaceInteger:nRead*,nPrint*,fac(n)End program example_12例13、 编一函数,求两数之和a) 用外部过程实现program example_131 implicit none integer:a,b,sum read*,a,b call add(a,b,sum) print*,sumend program example_131subroutine add(a,b,sum)implicit noneinteger,intent(in):a,binteger,intent(out):sumsum=a+bend subroutine addb) 用内部过程实现program exampl_132 implicit
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 城市排水防涝系统提升工程社会稳定风险评估报告
- 2025安徽庐阳城新集团(招商运营专场)社会公开招聘笔试历年备考题库附带答案详解试卷3套
- 2025城发环保能源(汝南)有限公司招聘4人笔试历年备考题库附带答案详解试卷3套
- 铅蓄电池生产流水线项目风险评估报告
- 2025中国能源建设集团甘肃省电力设计院有限公司校园招聘笔试历年常考点试题专练附带答案详解试卷3套
- 东乡区公务员考试试题及答案
- 德城区公务员考试试题及答案
- 水厂迁建工程技术方案
- 混凝土搅拌站能源管理与节能方案
- 纺织印染服装制造项目建设工程方案
- 2025建设工程消防验收电气专业常见问题
- 《山地城市道路工程海绵城市设计指南(征求意见稿)》
- 2025医学细胞生物学案例解析
- 2025-2030年中国酒吧行业资本规划与股权融资战略制定与实施研究报告
- 2024-2025学年广东省广州市部分学校高一(上)期中数学试卷(含答案)
- 糖尿病与睡眠障碍
- 农村土地使用权转让协议书
- 部编九年级上册语文第一单元教材知识点考点梳理 (共30张)+学案+验收卷(含答案)
- DB11T 1077-2020 建筑垃圾运输车辆标识、监控和密闭技术要求
- DB34∕T 2727-2016 厂拌沥青混凝土热风式再生工艺规程
- MAXHUB会议平板操作说明书
评论
0/150
提交评论