Fortran练习经典题目
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
a, 输入一个年、月、日并计算它是本年度的第几天。
b.输入任意一年份,给出该年出生人的属相,如1945年出生的人的属相为“鸡”。
c.显示输出2000~2099年的任何一年的某一月的月历,所要显示的年月有键盘输入。如2002年5月的月历形式如下;
5月2002年
日一二三四五六
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
d.显示输出2000~2099年的任何一年的年历,并写入一文本文件中。
e.以上功能都应从菜单中选择执行。
提示:a中若y为年份,d是该年的某月某日从1月1日开始经过的天数,则s=(y-1)*1.2425+d。若s除以7后所得的余数取整后为0,则为周日,为1则周一。program firstquestion
implicit none
integer::q,i,lday
integer::year,month,day,days,mday,ds
character(len=2),dimension(1:37)::tem
! 这个程序可以同时在屏幕和文本中输出计算结果。为了计算不同的问题,引入变量q,当q=1时,计算某年月日是此年的第几天;
! 当q=2时,计算某年的属相;当q=3时,计算月历;当q=4时,计算年历;当q=0时,退出此程序。此外,此程序还设置了对输入
! 年、月、日的判断,判断其是否合法。
print *,'when q=1,this program can resolve the question that which day some day is in some year! this is the question one.'
print *,'when q=2,this program can obtain the shengxiao of some year! this is the question two.'
print *,'when q=3,this program can obtain the calendar of some month of some year(2000-2099)! this is the question three.'
print *,'when q=4,this program can obtain the Almanac of some year(2000-2099)! this is the question four.'
print *,'If you want to exit from this program,please input q=0.'
do
print *,'input the number of q:'
read *,q
if(q==0) exit
if (q==1) then
2000 print *,'input the year, the month and the day:'
read *,year,month,day
if (month>12.or.month<0) print *,'you input wrong month.'
if (month>12.or.month<0) goto 2000
call leapday(year,month,day,lday)
if (lday==0) print *,'you input wrong day.'
if (lday==0) goto 2000
call numday(year,month,day,days)
print '(a14,i3,a18)','The day is the',days,' day of this year.'
open(25,file='days.dat',status='unknown')
write(25,'(a14,i3,a18)') 'The day is the',days,' day of this year.'
close(25)
else if (q==2) then
print *,'input the year:'
read *,year
call shengxiao(year)
else if (q==3) then
2001 print *,'input the year(2000-2099) and the month:'
read *,year,month
if (year>2099.or.year<2000) print *,'you input wrong year,please input the year between 2000 and 2099.'
if (year>2099.or.year<2000) goto 2001
if (month>12.or.month<0) print *,'you input wrong month.'
if (month>12.or.month<0) goto 2001
open(27,file='yueli.dat',status='unknown')
call nyli(year,month,mday,ds,tem)
write(27, "(26x,i2,'月',3x,i4,'年')")month,year
write(27, '(18x,7a4)')'日','一','二','三','四','五','六'
write(27, '(18x,7a4)')(tem(i),i=1,mday+ds)
write(27,*)
close(27)
else if (q==4) then
2002 print *,'input the year(2000-2099):'
read *,year
if (year>2099.or.year<2000) print *,'you input wrong year,pleade input the year between 2000 and 2099.' if (year>2099.or.year<2000) goto 2002
open(28,file='nianli.dat',status='unknown')
do month=1,12
call nyli(year,month,mday,ds,tem)
write(28, "(26x,i2,'月',3x,i4,'年')")month,year