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

Compile and Execute FORTRAN-95 Online

program ex1
! this program calculates area of triangle
real::b,h,area
read*,b,h
print*,'b=',b
Print *,'h=',h
area=b*b/2
print*'area of triangle=',area
end program ex1

Compile and Execute FORTRAN-95 Online

PROGRAM matmult
implicit none
   integer, dimension (:,:), allocatable :: array1
   integer, dimension (:,:), allocatable :: array2
   integer, dimension (:,:), allocatable :: array3
   integer :: L, M, N, i, j, k, k2, asum
   character (len = 15) :: l2, m2, n2


	! Prompt for 3 integers (call them L, M, and N)
	! They represent the dimensions of the arrays
	! The first array will be dimension L x M, the second will be M x N
	! and the product array, L x N
	
	CALL GET_COMMAND_ARGUMENT(1, l2)
	CALL GET_COMMAND_ARGUMENT(2, m2)
	CALL GET_COMMAND_ARGUMENT(3, n2)
	
	read(l2,'(i4)') L
	read(m2,'(i4)') M
	read(n2,'(i4)') N
	
	allocate (array1(L, M))
	allocate (array2(M, N))
	allocate (array3(L, N))

	
	! Initialize the first array such that array(i,j) = 10i+j
	do i = 1, L
        do j = 1, M
        array1(i,j) = (10*i)+j
        end do
    end do

	
	! Initialize the second array such that array(i,j) = 20i+2j
	do i = 1, M
        do j = 1, N
        array2(i,j) = (20*i)+(2*j)
        end do
    end do
    

	! Multiply arrays
	! Matrix multiplication C = AB
	!        C(i,j) = the sum product of row i of A and column j of B     
	do i = 1, L
        do j = 1, N
        

        do k = 1, M
            asum = asum + (array1(i, k) * array2(k, j))
        end do
        
        array3(i,j) = asum
        write (*,*) asum
        
        end do
    end do

	
	! Print the array row-by-row to STDOUT (terminal)
	! To print elements of an array in a row, you can define a loop as part of the WRITE
	! Assuming that vec is a one-dimensional array of length 5 and j is a declared variable,
	! the following will print that vector as a row
	! 		WRITE(*,*) (vec(j), j=1, 5)
	! L x N
	do i = 1, N
        WRITE(*,*) (array3(j,i), j=1, L)
    end do

	
	! Deallocate arrays
	! If you allocate it, you need to deallocate it
	deallocate (array1)
	deallocate (array2)
	deallocate (array3)

	
END PROGRAM matmult

prob4

program prob4
!mathematical operation
integer::m,n,i
m=0
n=1
do i=1,10
read*,a
m=m+a
n=n*a
end do
print*,"the sum of ten numbers is",m
print*,"the product of ten numbers is",n
end program prob4

prob1

program prob1
!print the square of numbers from one to ten
integer::i,x
do i=1,10
x=i**2
print*,'the square of',i,'=',x
end do
end program prob1

prob 2

program prob2
!mathematical operation
integer::x,y
y=0
do x=1,10
y=y+x
Print*,y
end do
end program prob2

prob2

program prob2
!mathematical operation
integer:: x,y,sum,i
read*,x,y
sum=0
do i=x,y
sum=sum+i
end do
Print*,sum
end program prob2

prob5

program prob5
!mathematical operation
integer:: x,low,high,step
read*, low,high,step 
do x=low,high,step
Print *,x
end do
end program prob5

EX 20

 program ex20
integer::a,b,c,d
read*,a,b
print *, 'a=' ,a
print *, 'b=',b
if (a<b) then
c=2*a*b
print *, '2*product =',c
else
d=2*(a+b)
print *,'2 sum=',d
end if 
end program ex20

EX 22

program ex22
integer::i
do i=0,20,10
print *,i
end do
end program ex22

EX 24

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

Previous 1 ... 5 6 7 8 9 10 11 ... 111 Next
Advertisements
Loading...

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