0

我需要知道,我的溢出算法有什么问题?,在 Fortran 中,我必须做一个算法来在达到溢出中断时返回增量“n”的数量。

program overflow

  integer::n,i,fact;

  fact = 1;
  n = 50;

  do i=1,n,1
     fact=fact*i;
     if ((fact==abs(fact)).and.(fact /= 0)) then
        print*,"F!=",fact;
        n=n+1;
        !print*,"Overflow=",n;
     end if;
  end do;   

  print*,n;

end program overflow

它包含负值,并且在达到表示“溢出”的数字之前的阶乘中的“突变”,但它是错误的,n 应该是 15。

4

1 回答 1

0

我从来都不是 Fortran 程序员,但也许你的返回值应该是双倍的。

于 2013-10-19T02:03:38.867 回答