回 帖 发 新 帖 刷新版面

主题:我是菜鸟中的菜鸟大哥大姐帮忙看看谢谢···

write(*,*)'enter x=?'
      read(*,*) x
      if(x.lt.28.0)then
      f=0.0
      else if( x.lt.30.0)then
      f=0.5*x-14.0
       elseif(x.lt.32.0)then
      f=-0.5*x+16.0
      else
      f=0.0
      endif
      write(*,*)'f(X)=',f
      end
     程序运行没节果不知道错哪了??

回复列表 (共2个回复)

沙发

program main
  implicit none
  real:: x, f
  
  x = 29.38
  if ( x < 28.0 ) then
    f = 0.0
  else if ( x < 30.0 ) then
    f = 0.5 * x - 14.0
  else if ( x < 32.0 ) then
    f = -0.5 * x + 16.0
  else
    f = 0.0
  end if
  write(*, *) "f(", X, ")=", f
 
  stop
end program main

板凳

你的程序 应该没错,但我建议你注意编程规范。

我来回复

您尚未登录,请登录后再回复。点此登录或注册