用Fortran语言编写:3.(1)循环输入一周日最高气温,判断其中最高气温,并计算一周平均最高气温。 2014年3月23日-29日南京日最高气温如下:(单位:℃) 16.0 17.5 17.0 18.0 16.8 22.0 24.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.0,10.0,9.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-11 13:03:27 浏览: 229
以下是用Fortran语言编写的代码:
(1)
```
program week_temperature
implicit none
integer :: i
real :: temp(7), max_temp, avg_temp
! 循环输入一周日最高气温
do i = 1, 7
write(*,*) "请输入第", i, "天的最高气温:"
read(*,*) temp(i)
end do
! 判断其中最高气温
max_temp = temp(1)
do i = 2, 7
if (temp(i) > max_temp) then
max_temp = temp(i)
end if
end do
! 计算一周平均最高气温
avg_temp = sum(temp) / 7
! 输出结果
write(*,*) "一周中最高气温为:", max_temp, "℃"
write(*,*) "一周平均最高气温为:", avg_temp, "℃"
end program week_temperature
```
(2)
```
program month_temperature
implicit none
integer :: i, max_index, min_index
real :: temp(28), max_temp, min_temp, avg_temp
character(len=10) :: date(28)
! 使用数组输入一月日最高气温
temp = [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.0, 10.0, 9.0, 13.0, 11.0, 14.0, 5.0, 6.0, 5.0, 10.0, 9.0, 10.0, 12.0, 13.0]
! 计算一月平均最高气温
avg_temp = sum(temp) / 28
! 判断其中最高、最低气温
max_temp = temp(1)
min_temp = temp(1)
max_index = 1
min_index = 1
do i = 2, 28
if (temp(i) > max_temp) then
max_temp = temp(i)
max_index = i
end if
if (temp(i) < min_temp) then
min_temp = temp(i)
min_index = i
end if
end do
! 输出最高、最低气温值及其在该月中的天数(第几天)、日期
date = ["2023/02/01", "2023/02/02", "2023/02/03", "2023/02/04", "2023/02/05", "2023/02/06", "2023/02/07", "2023/02/08", "2023/02/09", "2023/02/10", "2023/02/11", "2023/02/12", "2023/02/13", "2023/02/14", "2023/02/15", "2023/02/16", "2023/02/17", "2023/02/18", "2023/02/19", "2023/02/20", "2023/02/21", "2023/02/22", "2023/02/23", "2023/02/24", "2023/02/25", "2023/02/26", "2023/02/27", "2023/02/28"]
write(*,*) "一月中最高气温为:", max_temp, "℃,出现在第", max_index, "天,即", date(max_index)
write(*,*) "一月中最低气温为:", min_temp, "℃,出现在第", min_index, "天,即", date(min_index)
end program month_temperature
```
阅读全文