用fortran语言求1+2+3+4+5的值
时间: 2023-09-14 13:10:14 浏览: 175
fortran 数值算法
5星 · 资源好评率100%
以下是用Fortran语言编写的代码,可以计算1+2+3+4+5的值:
```
program sum
implicit none
integer :: i, sum
sum = 0
do i = 1, 5
sum = sum + i
end do
print *, "The sum of 1 to 5 is ", sum
end program sum
```
运行该程序,输出结果为:
```
The sum of 1 to 5 is 15
```
阅读全文