Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use dimension x(n) in main program in FORTRAN?

I want to make x(1),x(2),x(3),…,x(n) using dimension in FORTRAN.

Example :

n=10 
dimension x(n) 
do n=1,10
print*,x(n)
enddo
stop
end

But It’s not allowed as far as I know …
And I get this error :
"symbol N is not permitted in a specification expression Errors in declarations, no further processing for main"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I make x(1),x(2),x(3),…,x(n) ?

>Solution :

Best is to take a good text book to learn Fortran and look what the possibilities are in the Fortran language.

There are multiple ways e.g. using an allocatable:

integer, parameter :: n=10 
double precision :: x(:)
integer :: i
allocate(x(n))

do i=1,n
  x(i) = i
enddo

do i=1,n
  print*,x(i)
enddo

end

or using a fixed array:

integer, parameter :: n=10 
double precision :: x(n
integer :: i


do i=1,n
  x(i) = i
enddo

do i=1,n
  print*,x(i)
enddo

end
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading