In: Computer Science
Write a fortran 90 program that sets up a 4x4 2D real array A and associate a single value pointer AP with element (2,1) of that array. Set all elements in A equal to 0. and print the value of AP to the screen. Next set all elements in A equal to 1.23 and print the value AP to the screen.
Program Description
The program uses the statement
real, dimension(4,4)::A
To declare a two dimensional array (4X4) named A
real,pointer::AP
AP is a real pointer variable
AP=A(2,1)
As mentioned in the problem AP has been made associated with a single value A(2,1).
using do loop set the array elements to 0.
print the AP value. In this program write method has been used to do some format to print as AP=value.
Again use do loop to set the values in the array as 1.23.
Again print AP vlaue.
program ends
Code
program hello
real, dimension(4,4)::A ! Two Dimensional
Array
real, pointer::AP ! Pointer
AP=A(2,1) ! Associating the pointer to the single value
A(2,1)
!Loop to assign the array values as 0
do i=1,4
do j=1,4
A(i,j)=0
end do
end do
write (*,"(A,F7.2)"), "AP=",AP ! Printing AP
!Loop to assign the array values as 1.23
do i=1,4
do j=1,4
A(i,j)=1.23
end do
end do
write (*,"(A,F7.2)"), "AP=",AP ! Printing AP
end program hello
Output
AP= 0.00
AP= 0.00
Screenshot
Output
The Compiler used is online compiler.