Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Test1.for

program hello
   Print *, "Hello World!"
   goto 100
   stop
   100 write(*,*) "moin",sqrt(2.d0)
   call sub1
end program Hello
subroutine sub1
write(*,*) exp(1.d0)
return
end

Excercise 26

program ex26
integer::x,y
do x=10,0,-1
y=2*x+5 
print *,y
end do 
end program ex26

Excercise 24

program ex24
integer ::i,sum
sum=0
do i=1,5
sum=sum+i**2
end do
print *,'sum of the squqares from 1 to 5=' ,sum
end program ex24

Excercise 23

program ex23
integer::i,prod
prod=1
do i=1,6
prod=prod*i
end do 
print *, 'prod from 1 to 6 =' ,prod
end program ex23

Compile and Execute FORTRAN-95 Online

program ex13
integer::m,x
read*,m,x
c=m+3*x
print *,d
end program ex13

Compile and Execute FORTRAN-95 Online

program ex10
integer::a,b
read*,a,b
c=a**2-b**2
print *,c
end program ex10

Compile and Execute FORTRAN-95 Online

program ex4
   !this program calculates twice the sum of two numbers 
   integer::a,b
   read*,a,b
   x=2*(a+b)
   print*,x
end program ex4

ex25

program ex25
ineger ::x,y
do x=0,20,2
y=4*x-
print *,y
end do
end program ex25

ex18c

program ex18c
!mathematical operation
real:: x,y
read *, x
if(x>-1) then
y=2*x**2+3
print *, 'the value of y is=' ,y
else
y=x-5
print *,'the  value of y is=' ,y
end if 
end program ex18c

Compile and Execute FORTRAN-95 Online

program hello
implicit none
   integer, dimension (:,:), allocatable :: darray
   integer, target, dimension (:), allocatable :: sortarray
   integer, target, dimension (:), allocatable :: narray
   integer :: i, j, n, k
   character (len = 15) :: input_file
   character (len = 15) :: output_file
   integer :: columns = 0, rows = 0, middleman = 0
   
   !get arguments
   CALL GET_COMMAND_ARGUMENT(1, input_file)
   CALL GET_COMMAND_ARGUMENT(2, output_file)
   print *, input_file
   print *, output_file
   
   write(*,*)input_file

   !open file for reading
   open (unit = 1, file = input_file, status = 'old')
   read(1, *) columns, rows
   !print "(i6)", columns
   !print "(i6)", rows

   !fill array
   allocate (darray(columns,rows))
   allocate (narray(columns))
   allocate (sortarray(columns))
   
   !get rows
    do i = 1, rows
        read(1, *) narray
        print *, narray
        !print *,'before = ', narray
        
        !sort a row
        do n = 1, columns
            do j = 1, (columns-n)
            if(narray(j) .gt. narray(j+1)) then
                middleman = narray(j)
                narray(j) = narray(j+1)
                narray(j+1) = middleman
            end if
            end do
        end do
        
        do j = 1, columns
            darray(j,i) = narray(j)
        end do
        !print *,'after= ', darray
   end do
   close(1)
   
   open (unit = 2, file = output_file, status = 'new')
   
   !sort columns
   do i = 1, rows
        do j = 1, (rows-i)
        if(darray(1,j) .gt. darray(1,(j+1))) then
            do k = 1, columns
                middleman = darray(k,(j))
                darray(k, j) = darray(k, (j+1))
                darray(k, (j+1)) = middleman
            end do
        end if
        end do
        
        !print row to file
        do k = 1, columns
            write(2, *) darray(i,k)
        end do
        write(2, *) '/'
        
   end do
   !print *,'should be sorted = ', darray
   close(2)
   
   
end program Hello

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.