I have a problem with my Fortran program, which does nothing more than calculate simple factorization (or should do). What a mistake:
C:\MinGW\Fortran>gfortran aufg3.f90 aufg3.f90:15.15: if (prim(i) != 0 .and. modulo(n, prim(i)) == 0) then 1 Error: Missing ')' in statement at or before (1) aufg3.f90:19.7: end if 1 Error: Expecting END DO statement at (1) aufg3.f90:34.13: if (prim(i) != 0) then 1 Error: Missing ')' in statement at or before (1) aufg3.f90:38.5: end if 1 Error: Expecting END DO statement at (1)
I tried everything, but I don’t know at all what could be wrong. Thank you for your help. Here is the code:
program aufg3 implicit none integer :: n, i integer, allocatable, dimension(:) :: prim do print *, 'Bitte natürliche Zahl eingeben, "0" für Abbruch: ' read *, n if (n == 0) exit allocate(prim(2:n)) call era(prim, n) print *, n, ' = 1' do if (n == 1) exit do i = 2, n if (prim(i) != 0 .and. modulo(n, prim(i)) == 0) then print *, ' * ', prim(i) n = n / prim(i) exit end if end do end do deallocate(prim) end do end program
subroutine era(prim, m) integer, intent(in) :: m integer, dimension(2:m) :: prim integer :: i, j do i = 2, m prim(i) = i end do do i = 2, integer(sqrt(real(m))) if (prim(i) != 0) then do j = i*i, m, i prim(j) = 0 end do end if end do end subroutine
source share