Write a program that shows the dynamic memory allocation? - FORTRAN
Write a program that shows the dynamic memory allocation?
- Dynamic memory allocation is an essential part as it makes the program more flexible and provides lots of operations to be used.
- This program doesn’t contain the DO loops and IF/THEN statements that is used to manipulating the array.
- It consists of mathematical operations that are applied on the complete system including the array and provide the coding in a structured way.
- The program is shown as:
real, dimension(:), allocatable :: points
integer :: number_of_points
real :: average_points=0., positive_average=0., negative_average=0.
write (*,*) "Input number of points to average:"
read (*,*) number_of_points
write (*,*) "Enter the points to average:"
read (*,*) points
if (number_of_points > 0) average_points = sum(points) / number_of_points
if (count(points < 0.) > 0) then
negative_average = sum(points, points < 0.) / count(points < 0.)
write (*,'(a,g12.4)') 'Average = ', average_points