编辑代码

Program SummingUp
implicit none
integer:: i,j,sum
!read the variable
write(*,'(a)') 'Type a integer variable that is > 0'
read(*,*) i
!Check whether i>0
if(i>0)then
!initialize sum at 0
sum =0
  
!do the summing up
do j=1,i
sum=sum+j
enddo
!write the result to the console
write (*,'(a,i3,a,i10)') 'The sum of 1 to ',i,' is ',sum
else

!write the error message
write(*,'(a)') 'Error: i should be greater than 0'  

endif
end program