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.
program t25
!count and print all numbers from low to high
integer::low,high,step,a
read*,low,high,step
do a=low,high,step
print*,a
end do
end program t25
program t22
!sum of numbers from low to high
integer::x,y,sum,i
read*,x,y
print*,"low number is",x
print*,"high number is",y
sum=0
do i=x,y
sum=sum+i
end do
Print *,'the sum from low to high',sum
end program t22
program test2
!sum of numbers from low to high
integer::x,y,sum,i
read*,x,y
print*,'the low number is',x
print*,'the high number is',y
sum=0
do i=x,y
sum=sum+i
end do
print*,'the sum from low to high number is',sum
end program test2
program assign6
implicit none
CHARACTER(LEN=20) :: file1name, file2name
integer :: row
integer :: col
integer :: i
integer, dimension(:,:), allocatable :: myarray
CALL get_command_argument(1, file1name)
CALL get_command_argument(2, file2name)
open(1, file = file1name, action='read',status='old')
READ(1,*) row, col
allocate( myarray(row, col))
! read first line of file
! first value in first line is row/height
! second value in first line is column/width
DO i =1, row
READ(1,*) myarray(i, :)
write(*,*) myarray(i, :)
END DO
deallocate( myarray)
close(1)
end program
!length parameter
!value parate
!value
!parameter to open call
!3 nested loops
!one loop to read in
!one loop to sort the first value of the rows
!one loop to sort the values of each column
PROGRAM matmult
implicit none
!! Declarations
! Define 3 allocatable 2-dimensional integer arrays
! and any temporary variables that you need
integer, dimension (:,:), allocatable :: array1
integer, dimension (:,:), allocatable :: array2
integer, dimension (:,:), allocatable :: array3
integer, dimension (:), allocatable :: printarray
integer :: l, m, n
integer :: i, j
integer :: temp, x
!! Create and initialize arrays
! 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
write(*,*) 'Enter array dimensions'
read(*,*) l, m, n
! Allocate the 3 arrays of the correct size
allocate (array1(l,m))
allocate (array2(m,n))
allocate (array3(l,n))
!! Initialize arrays
! Initialize the first array such that array(i,j) = 10i+j
do i = 1, m
do j = 1, l
array1(i, j) = (10*i)+j
end do
end do
! Initialize the second array such that array(i,j) = 20i+2j
do i = 1, n
do j = 1, m
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, n
do j = 1, l
temp = 0
do x = 1, n
temp = temp + array1(j,x) * array2(x,j)
end do
array3(i, j) = temp
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)
allocate(printarray(l))
do i = 1, n
do j = 1, l
printarray(j) = array3(j, i)
end do
write(*,*) printarray
end do
! Deallocate arrays
! If you allocate it, you need to deallocate it
deallocate(array1)
deallocate(array2)
deallocate(array3)
deallocate(printarray)
END PROGRAM matmult