Fortran Coder

查看: 20563|回复: 9
打印 上一主题 下一主题

[求助] Fortran判断是否为闰年

[复制链接]

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
跳转到指定楼层
楼主
发表于 2020-7-2 09:15:10 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
Fortran判断是否为闰年,求教老师看一下哪里出错
[Fortran] 纯文本查看 复制代码
program test0504
implicit none
integer year
write(*,*) "Please input the yaer:"
read(*,*) year
!if((mod(yaer,4.0)==0).or.(mod(yaer,100.0)==0.and.mod(yaer,400.0)==0)) then
if((yaer%4.0==0.0).or.(yaer%100.0==0.0.and.yaer%400.0==0.0)) then
write(*,*) "This year is a leap yaer."
else
write(*,*) "This year is not a leap yaer."
end if
stop
end

错误:
错误        1         error #5082: Syntax error, found REAL_CONSTANT '4.0' when expecting one of: <IDENTIFIER> [              
错误        2         error #5082: Syntax error, found REAL_CONSTANT '100.0' when expecting one of: <IDENTIFIER> [        
错误        3         error #5082: Syntax error, found REAL_CONSTANT '400.0' when expecting one of: <IDENTIFIER> [               
错误        4         error #5082: Syntax error, found ')' when expecting one of: , (/ : ]        
错误        5        Compilation Aborted (code 1)        



分享到:  微信微信
收藏收藏 点赞点赞 点踩点踩

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
沙发
 楼主| 发表于 2020-7-3 09:09:49 | 显示全部楼层
谢谢各位老师,改好的程序如下,可以正常运行了
[Fortran] 纯文本查看 复制代码
program test0504
  implicit none
  integer year
  write(*,*) "Please input the yaer:"
  read(*,*) year
  if((mod(year,400)==0).or.(mod(year,100)/=0.and.mod(year,4)==0)) then
   write(*,*) "This year is a leap yaer."
  else
   write(*,*) "This year is not a leap yaer."
  end if
  stop
end program test0504

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
板凳
 楼主| 发表于 2020-7-3 09:25:09 | 显示全部楼层
liudy02 发表于 2020-7-3 00:21
这个写法不符合尽量减少计算量的原则,虽然没啥大影响……
最节省计算量的写法应该是三个表达式的次序完 ...

谢谢老师的指教,问题处理好了

25

帖子

8

主题

0

精华

熟手

F 币
143 元
贡献
81 点
地板
 楼主| 发表于 2020-7-14 10:45:36 | 显示全部楼层
收到,谢谢老师
您需要登录后才可以回帖 登录 | 极速注册

本版积分规则

捐赠本站|Archiver|关于我们 About Us|小黑屋|Fcode ( 京ICP备18005632-2号 )

GMT+8, 2024-5-9 06:28

Powered by Tencent X3.4

© 2013-2024 Tencent

快速回复 返回顶部 返回列表