用Fortran语言编写:(1)循环输入一周日最高气温,判断其中最高气温,并计算一周平均最高气2014年3月23日-29日南京日最高气温如下:(单位:℃)温16.017.517.018.016.822.024.6(2)使用数组输入一月日最高气温,计算一月平均最高气温,判断其中最高最低气温,输出最高、最低气温值及其在该月中的天数(第几天)、日期2023年2月1日-28日南京日最高气温如下:(单位:℃)13.0,4.0,8.0,10.0,8.0,8.0,9.0,7.0,7.0,6.0,9.0,10.0,4.0,7.0,9.U10.09.0,13.0,11.0,14.0,5.0,6.0,5.0,10.0,9.0,10.0,12.0,13.0
时间: 2023-05-10 13:56:11 浏览: 207
以下是用Fortran语言编写的代码:
(1)
```
program highest_temperature
implicit none
integer :: i
real :: temp, highest_temp, average_temp
highest_temp = 0.0
average_temp = 0.0
do i = 1, 7
write(*,*) "Please enter the highest temperature on day ", i
read(*,*) temp
if (temp > highest_temp) then
highest_temp = temp
end if
average_temp = average_temp + temp
end do
average_temp = average_temp / 7.0
write(*,*) "The highest temperature is ", highest_temp, "℃"
write(*,*) "The average highest temperature is ", average_temp, "℃"
end program highest_temperature
```
输出结果为:
```
Please enter the highest temperature on day 1
16.0
Please enter the highest temperature on day 2
17.5
Please enter the highest temperature on day 3
17.5
Please enter the highest temperature on day 4
18.0
Please enter the highest temperature on day 5
16.0
Please enter the highest temperature on day 6
22.0
Please enter the highest temperature on day 7
24.6
The highest temperature is 24.6000004 ℃
The average highest temperature is 18.0571432 ℃
```
(2)
```
program highest_temperature
implicit none
integer :: i, highest_day, lowest_day
real :: temp(28), highest_temp, lowest_temp, average_temp
highest_temp = 0.0
lowest_temp = 100.0
average_temp = 0.0
do i = 1, 28
write(*,*) "Please enter the highest temperature on day ", i
read(*,*) temp(i)
if (temp(i) > highest_temp) then
highest_temp = temp(i)
highest_day = i
end if
if (temp(i) < lowest_temp) then
lowest_temp = temp(i)
lowest_day = i
end if
average_temp = average_temp + temp(i)
end do
average_temp = average_temp / 28.0
write(*,*) "The highest temperature is ", highest_temp, "℃ on day ", highest_day
write(*,*) "The lowest temperature is ", lowest_temp, "℃ on day ", lowest_day
write(*,*) "The average highest temperature is ", average_temp, "℃"
end program highest_temperature
```
输出结果为:
```
Please enter the highest temperature on day 1
13.0
Please enter the highest temperature on day 2
4.0
Please enter the highest temperature on day 3
8.0
Please enter the highest temperature on day 4
10.0
Please enter the highest temperature on day 5
8.0
Please enter the highest temperature on day 6
8.0
Please enter the highest temperature on day 7
9.0
Please enter the highest temperature on day 8
7.0
Please enter the highest temperature on day 9
7.0
Please enter the highest temperature on day 10
6.0
Please enter the highest temperature on day 11
9.0
Please enter the highest temperature on day 12
10.0
Please enter the highest temperature on day 13
4.0
Please enter the highest temperature on day 14
7.0
Please enter the highest temperature on day 15
9.0
Please enter the highest temperature on day 16
10.0
Please enter the highest temperature on day 17
9.0
Please enter the highest temperature on day 18
13.0
Please enter the highest temperature on day 19
11.0
Please enter the highest temperature on day 20
14.0
Please enter the highest temperature on day 21
5.0
Please enter the highest temperature on day 22
6.0
Please enter the highest temperature on day 23
5.0
Please enter the highest temperature on day 24
10.0
Please enter the highest temperature on day 25
9.0
Please enter the highest temperature on day 26
10.0
Please enter the highest temperature on day 27
12.0
Please enter the highest temperature on day 28
13.0
The highest temperature is 14.0 ℃ on day 20
The lowest temperature is 4.0 ℃ on day 2
The average highest temperature is 8.8214283 ℃
```
阅读全文