用fortran编写:依次输入10个同学成绩,系统自动选出其中最大成绩
时间: 2023-12-03 20:44:19 浏览: 37
下面是用 Fortran 编写的程序,可以依次输入 10 个同学的成绩,并找出其中的最大值:
```fortran
program maxscore
implicit none
integer :: i, n = 10, maxscore = 0, score
write(*,*) '请输入', n, '个同学的成绩:'
do i = 1, n
read(*,*) score
if (score > maxscore) then
maxscore = score
end if
end do
write(*,*) '最大成绩为:', maxscore
end program maxscore
```
在上面的程序中,我们定义了一个整数变量 `maxscore` 来存储最大成绩,初始值为 0。然后使用一个 do 循环来依次读入 10 个同学的成绩,每次读入一个成绩后,将其与 `maxscore` 比较,如果大于 `maxscore`,则将其赋值给 `maxscore`。最后输出 `maxscore` 即可。
相关问题
用fortran编写:输入一个小写字母,将其转换为大写字母后输出。
可以使用 Fortran 的 ASCII 函数来实现这个功能。
首先,使用 `read` 语句输入一个字符:
```fortran
character :: c
read(*,*) c
```
然后,使用 ASCII 函数将字符转换为 ASCII 码:
```fortran
ascii = int(c)
```
接下来,判断该字符是否为小写字母,如果是,就将其转换为大写字母:
```fortran
if (ascii >= 97) then
ascii = ascii - 32
endif
```
最后,使用 ASCII 函数将 ASCII 码转换回字符,并使用 `write` 语句输出:
```fortran
c = char(ascii)
write(*,*) c
```
完整的程序如下:
```fortran
program main
character :: c
integer :: ascii
read(*,*) c
ascii = int(c)
if (ascii >= 97) then
ascii = ascii - 32
endif
c = char(ascii)
write(*,*) c
end program main
```
用fortran语言编写:从键盘输入十个数,要求按输入时的逆序输出
你好!下面是一个例子,如何用Fortran语言从键盘输入十个数并按逆序输出:
program inverse_input
implicit none
integer :: i, n, a(10)
! 从键盘输入十个数
do i = 1, 10
write(*,'(A)') '请输入一个数:'
read(*,'(I5)') n
a(i) = n
end do
! 按输入时的逆序输出
do i = 10, 1, -1
write(*,'(I5)') a(i)
end do
end program inverse_input
在这个例子中,我们定义了一个整数数组a,用来存储从键盘输入的十个数。然后,我们使用一个循环从键盘输入这十个数,并将它们存储在数组a中。最后,我们使用另一个循环按逆序输出数组a中的数。
希望这能帮到你!如果你有其他问题,请随时追问。