algorithm - Problem creating a frequency array of a given array -
i trying create frequency array of given array on fortran 95. instance if have array (\1 2 4 2 4 2 5), frequency array should number of times each item appears; (\1 3 2 3 2 3 1). because there 1 of 5s in original array, last entry in new array 1 , because there 3 of 2s in original array, corresponding entries on new array 2.
below sample of code have, keep getting errors. wondering if willing give me guidance , on doing wrong. appreciated.
i haven't included part of code generates original array because i'm pretty sure correct here subroutine frequency array. original array sorted in ascending order outside subroutine. perhaps didn't pass original array, num(i) correctly??
integer, dimension(100)::num(100) integer, dimension(100)::freq(100) integer:: i=0, k=0, numinteger, count=0 call freqarray(num, numinteger,freq) subroutine freqarray(num, numinteger, freq) integer, intent(in):: num(100), numinteger integer, intent(out):: freq(100) i=1,9 count=0 k=1, numinteger if (num(k)==i)then count=count+1 end if end freq(i)=count end print*, "frequency of digits" print*, " " write(*,'(1x,a,t35,a)'),"digit","frequency" write(*,'(1x,i1,t35,i1)'),num(i),freq(i) end subroutine thanks time.
with regards display issue, suspect meant have loop around
write(*,'(1x,i1,t35,i1)'),num(i),freq(i)
Comments
Post a Comment