推 swarm:全部的變數都宣告成real看看140.112.252.171 03/24
我寫了一個小程式
當然 是要交作業用的
用fortran寫的
程式碼如下
program Q2_b_5_digits
implicit none
real, parameter :: short_real = selected_real_kind(5,5)
real(kind=short_real) :: x
real A, B
integer :: n, l
l=0
write(*,*) "This is a little program to help you calculate the sequence of x."
write(*,*) "Current relation of x : x<n> = A*(1/3)^n + B*4^n"
write(*,*) "Please enter the constants A & B that you want:"
write(*,*) "A=?"
read(*,*) A
write(*,*) "B=?"
read(*,*) B
write(*,*) "How many terms do you need?"
write(*,*) "n=?"
read(*,*) n
do while(l<n)
x = A/(3**l) + B*(4**l)
l=l+1
write(*,*) "The",l-1,"th term of x is :"
write(*,'(E15.5)') x
end do
end program Q2_b_5_digits
--
現在我把x的數列當成x=(1/3)^n
也就是A=1 B=0
我的問題是
為什麼到25項以後就會出現負的?
我把x變成 x=x/3 ->就正常了
到底是為什麼勒
還有
為什麼電腦覺得1/3=0
我也不甚了解
--
時光匆匆匆匆溜走 也也也不回頭
美女變成老太婆
唉呦那那那個時候 我我我我也也
娶了很多小老婆 XD
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.188.198