基本上是用Fortran写的,主要是为了效率和精确度 如下: 1、史瓦西半径计算

program testingInt
  implicit none
  real(kind=16) :: G !这个宇宙的万有引力常数
  real(kind=16) :: M !天体质量,单位kg
  real(kind=16) :: c !这个宇宙的光速
  real(kind=16) :: R !史瓦西半径
  G = 6.67430e-11_16
  c = 299792458.0_16
  !print *,G 
  print *, "请输入物体质量M(单位:kg)"
  read *, M
  R=(2*G*M)/(c**2)
  print *, "半径为:", R
end program

2、钟慢尺缩效应

program testingInt
    implicit none
    real(kind=16) :: c
    real :: v_input
    real :: begin
    real(kind=16) :: out
    c = 299792458.0_16
    print *, "输入一个速度:"
    read *, v_input
    print *, "输入一个距离(m)/时间(s):"
    read *, begin
    if (v_input <= c) then
        out=begin*sqrt(1-(v_input**2/c**2))
        print *, "计算结果为:", out
    else
        print *, "输入的速度超过了光速,请重新输入一个小于光速的速度。"
    end if
end program