作者ganhua (GanHuaWang)
看板Fortran
标题[问题] 读取档案数据并求最大最小值
时间Fri Nov 2 12:08:05 2018
大家好,最近学了fortran程式,还不是很熟,这边有个小问题要请教大家,问题如下
Write a Fortran that will read an arbitrary number of non-negative real
values and find the maximum and minimum of the input data.
To test your program, input the following data from a data file (x.txt) and use IOSTAT in
read command to determine the number of data points to be processed.
Print the number of data points and the maximum and minimum you find.
97,28,66,87,15,95,45,67,76,65,73,88,69,90,63,25,47,70,63,99,61,79,10,92,36,89
前面读数据的部分我已经解决,问题是如何读进来後如何用Max和min函数来找最大最小值@@
助教有打一些提示(?)教我们怎麽找
https://imgur.com/a/OdZqTLX
https://imgur.com/a/VC6vPdo
可是这是从萤幕手动输入的写法,换成数据我就不太会了,= =还希望版上大神可以帮帮
期中快要爆炸的小弟Orz
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.112.25.45
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Fortran/M.1541131690.A.CED.html
1F:→ rex0707: read(*,*) x 改成 read(UNIT=file_unit,*) x 就可以了吧? 11/02 13:23
2F:→ rex0707: 如果是读进来存到阵列 就用MAXVAL、MINVAL找阵列的最大、 11/02 13:24
3F:→ rex0707: 小值 11/02 13:24
https://imgur.com/a/6DDAtBm
附上小弟的程式图(用的是cygwing64),不过执行後会跑出如下图
https://imgur.com/a/LzKRnvS
不知道问题在哪里@@
※ 编辑: ganhua (140.112.241.23), 11/02/2018 22:10:58
4F:→ rex0707: 试试看"read(30,10...) data"的回圈结束之後先关掉档案 11/03 13:57
5F:→ rex0707: "do while(x>0)" 之前再打开档案一次 11/03 13:57
6F:→ rex0707: 还有data本身就是复数 不需要加s 11/03 13:57
7F:推 espresso1: 因为第一个do loop已经read到档案底了,重头read要在do 11/03 16:08
8F:→ espresso1: while前先rewind(30) 11/03 16:08
了解,我过几天试试看,先准备其他科期中QQ
※ 编辑: ganhua (140.112.241.23), 11/04/2018 09:24:37