用Fortran语言,气象中降雪量的分级如下: 种类 12h降雪量(mm) 小雪 0.1≤R12<0.25 中雪 0.25≤R12<3.0 大雪 3.0≤R12<5.0 暴雪 R12≥5.0 请从键盘上输入某地某日12h降雪量,并输出当日该地降雪等级。
时间: 2024-02-20 17:57:00 浏览: 19
下面是一个简单的Fortran程序,可以实现输入12小时降雪量并输出降雪等级的功能:
```fortran
program snowfall
implicit none
real :: R12
write(*,*) '请输入某地某日12小时降雪量(mm):'
read(*,*) R12
if (R12 >= 5.0) then
write(*,*) '暴雪'
else if (R12 >= 3.0) then
write(*,*) '大雪'
else if (R12 >= 0.25) then
write(*,*) '中雪'
else if (R12 >= 0.1) then
write(*,*) '小雪'
else
write(*,*) '无降雪'
end if
end program snowfall
```
程序中使用了 if-else if-else 结构,根据输入的12小时降雪量 R12 的大小,判断其所属的降雪等级,并输出相应的结果。
相关问题
用Fortran语言编写:寻找书名中有“Fortran”的书
我们可以使用Fortran中的字符串函数来查找字符串中是否包含子串,然后在书名列表中寻找带有“Fortran”的书名。
下面是一个展示如何寻找书名中包含“Fortran”的Fortran程序示例。
```
program find_fortran_books
character(100):: books(5)
character(7):: search_str = 'Fortran'
integer:: i, count
! 书名列表
books(:) = (/'Advanced Fortran Programming',
'Numerical Methods in Fortran',
'Introduction to Fortran Programming',
'Fortran for Scientists and Engineers',
'Programming in Fortran 90 and 95'/)
! 判断每个书名是否包含“Fortran”
count = 0
do i = 1, 5
if (index(books(i), search_str) > 0) then
count = count + 1
write(*,*) books(i)
end if
end do
! 输出找到的书籍数量
write(*,*) 'Total number of books with Fortran in title:', count
end program find_fortran_books
```
运行该程序将输出带有“Fortran”的书名和总数。
用Fortran语言编写:从一百本图书中寻找书名中有“Fortran”的书
程序如下:
```
program find_books
character(30) :: book_titles(100)
integer :: i, count
! 输入100本书的书名
write(*, *) "请输入100本书的书名:"
do i = 1, 100
write(*, *) "第", i, "本书的书名:"
read(*, '(a)') book_titles(i)
end do
! 寻找书名中含有“Fortran”的书
count = 0
write(*, *) "书名中含有“Fortran”的书有:"
do i = 1, 100
if (index(book_titles(i), "Fortran") /= 0) then
write(*, *) book_titles(i)
count = count + 1
end if
end do
! 输出寻找结果
if (count == 0) then
write(*, *) "没有找到书名中含有“Fortran”的书。"
else
write(*, *) "共找到", count, "本书名中含有“Fortran”的书。"
end if
end program find_books
```
说明:
1. 定义一个字符数组`book_titles`存储100本书的书名。
2. 采用do循环输入100本书的书名。
3. 采用do循环查找书名中含有“Fortran”的书,并统计数量。
4. 输出查找结果。