Fortran练习经典题目

更新时间:2023-06-19 23:24:27 阅读: 评论:0

Fortran练习经典题目
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,plea input q=0.'
do
print *,'input the number of q:'
read *,q
kunmingif(q==0) exit
if (q==1) then
2000 print *,'input the year, the month and the day:'
read *,year,month,day
if (month&th<0) print *,'you input wrong month.'
if (month&th<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.'
带月的诗clo(25)
el if (q==2) then
print *,'input the year:'
read *,year
call shengxiao(year)
el if (q==3) then
2001 print *,'input the year(2000-2099) and the month:'
read *,year,month
if (year&ar<2000) print *,'you input wrong year,plea input the year between 2000 and 2099.'
if (year&ar<2000) goto 2001
if (month&th<0) print *,'you input wrong month.'
if (month&th<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,*)
clo(27)
el if (q==4) then
2002 print *,'input the year(2000-2099):'
read *,year
if (year&ar<2000) print *,'you input wrong year,pleade input the year between 2000 and 2099.' if (year&ar<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
write(28, '(18x,7a4)')'日','一','二','三','四','五','六'
write(28, '(18x,7a4)')(tem(i),i=1,mday+ds)
write(28,*)
end do
clo(28)
el
print *,'you input the wrong number of q.'
end if
end do
end program firstquestion
subroutine shengxiao(year)
implicit none
integer::year,m,n
m=year-1945
if (m>=12.or.m<=-12) then
n=mod(m,12)
el
n=m
end if泌尿外科出科小结
open(26,file='shengxiao.dat',status='unknown')
艾灸作用
if (n==0) then
print *,'The shengxiao of this year is:鸡'
write(26,*)'The shengxiao of this year is:鸡'
el if(n==1.or.n==-11) then
print *,'The shengxiao of this year is:狗'
write(26,*)'The shengxiao of this year is:狗'
el if(n==2.or.n==-10) then
print *,'The shengxiao of this year is:猪'
write(26,*)'The shengxiao of this year is:猪'
el if(n==3.or.n==-9) then
熏衣草花语print *,'The shengxiao of this year is:鼠'
write(26,*)'The shengxiao of this year is:鼠'
el if(n==4.or.n==-8) then
print *,'The shengxiao of this year is:牛'
write(26,*)'The shengxiao of this year is:牛'
el if(n==5.or.n==-7) then
print *,'The shengxiao of this year is:虎'
write(26,*)'The shengxiao of this year is:虎' el if(n==6.or.n==-6) then
print *,'The shengxiao of this year is:兔'
write(26,*)'The shengxiao of this year is:兔' el if(n==7.or.n==-5) then
print *,'The shengxiao of this year is:尨'
write(26,*)'The shengxiao of this year is:尨' el if(n==8.or.n==-4) then
print *,'The shengxiao of this year is:蛇'
write(26,*)'The shengxiao of this year is:蛇' el if(n==9.or.n==-3) then
print *,'The shengxiao of this year is:马'
write(26,*)'The shengxiao of this year is:马' el if(n==10.or.n==-2) then

本文发布于:2023-06-19 23:24:27,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/994317.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:输出   计算   判断   程序   问题   输入   年份   任意
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图