作者Faramir (法拉墨)
看板Fortran
标题Re: [问题] 简单的排序问题(内有程式)麻烦指教
时间Mon Jul 12 19:54:48 2010
我提供我以前作业的写法如下:
program main
integer(kind=2),allocatable::A(:)
integer(kind=2) n,i,j,temp
open(10,file='student.dat')
write(*,*) "有几个值要比较?"
read(*,*) n
allocate(A(n))
read(10,*) (A(j),j=1,n)
do i=n,1,-1
do j=1,i-1
if(A(j)<A(j+1))then
temp=A(j)
A(j)=A(j+1)
A(j+1)=temp
endif
enddo
enddo
write(*,*) A
stop
end
※ 引述《tn606523 (噜咪)》之铭言:
: 我写完跑排序由小到大的程式後,可是跑出来的值变成如下,可是我只是跑分数大小而已啊
: 怎麽会出这些数字啊?不知道有没有人能帮我解惑!谢谢!
: 157076596
: 157076520
: 134603550
: 134603542
: 134603535
: 16777216
: 16777216
: 7521472
: 7521312
: 7521312
: 2752534
: 2686998
: 2686998
: 2031707
: 2031707
: 2031707
: 720897
: 720897
: 720897
: 7609
: 92
: 92
: 63
: 5
: 1
: 1
: 1
: 1
: 1
: 1
: 1
: 1
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: 0
: -5
: -6
: 程式如下展示!我觉得是我的程式一定哪里有错误!可是我却无法理解!麻烦高手告诉我一下!
: program test
: implicit none
: integer A(j),c,d,b,i,j
: open(10,file='student.dat')
: i=0
: do
: read(10,*,end=999)c
: i=i+1
: enddo
: 999 continue
: do j=1,i
: read(10,*,end=998)A(j)
: enddo
: 998 continue
: j=1
: do while(j.lt.i)
: if(A(j).lt.A(j+1))then
: d=A(j)
: b=A(j+1)
: A(j)=b
: A(j+1)=d
: j=0
: endif
: j=j+1
: enddo
: do j=1,i
: write(*,*)A(j)
: enddo
: stop
: end
--
◢◤ ◥◤ ◥◤ ◣ 中原人的专属聊天园地 天南地北黑白聊
██中◤◥◣原◤◥◣大◤◥◣学 ‧天 人 物 我‧全 人 中 原‧
█▎ █ █ █▊◢█◣◢ ◣◢█◣█ █ ███◢█◣█ █◢◤
█▎ █ █ █▊█ ◥█◤█ █ █ █ █▄██ █ ◆
█▎ █ █ █▊◥█◤ █ ◥█◤◥█◤▄▄ █ █ ████◥◣
◥▎ ◥ ◥ ◥▊ CYCU_Talk板 欢迎您 ψby zachary28
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.132.137.192