In: Computer Science
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average.
An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade is any score that is not an F, but is at least 10% less than the average. Any scores that are within 10% of the average (either less than or greater than) are C's.
program average_calculation
implicit none
integer, allocatable,dimension(:):: vector
! creating a vector
integer :: elements,i,greater_elements
real :: average,total
print *,'enter the number of elements in the vector'
read *,elements
! elements will store the no of elements in a vector
allocate(vector(elements))
!allocates the correct amount of memory
total=0.0
greater_elements=0
!greater_elements will store the number of elements greater than average
print *,' your vector is of size ',elements,'. Now enter each element'
do i=1,elements
read *,vector(i)
total=total+vector(i) ! here above it is calculating the sum of total elements in vector
end do
average=total/elements
! calculating the average
print *,'This is your vector'
do i=1,elements
print *,vector(i)
if (vector(i)>average) then
greater_elements=greater_elements+1 !checking the elements greater than the averae
end if
end do
print *,' numbers of elements greater than average is = '
print *,greater_elements
deallocate(vector)
!free up the memory
end program average_calculation