开发者

Problem with Array Sorting and Printing it sideways in Fortran 95

开发者 https://www.devze.com 2023-02-23 20:38 出处:网络
I am trying to take my array of numbers based on a variable that determines its size and sort it. The array is created using the random numbers seed on Fortran 95. However when I try to sort it I ru

I am trying to take my array of numbers based on a variable that determines its size and sort it.

The array is created using the random numbers seed on Fortran 95. However when I try to sort it I run into big trouble. It compiles fine, but the array is printed with a lot of asterisks in it.

In addition I wante开发者_StackOverflowd to print my array sideways, (for instance something like this: 1 2 3 4 etc.) but I even failed at doing that. I realize that it must be done using the Advance="no" within a DO loop, but apparently that is erroneous as well.

Below is the code that I am using. If anyone is willing to let me know where I may be wrong I would be very grateful. Thanks for your time.

    SUBROUTINE Sorter(num, numinteger)

    INTEGER, INTENT(OUT):: num(100)
    INTEGER, INTENT(IN):: numinteger

    DO i=1, (numinteger-1)
        min=num(i)
        pos=i
        DO j=i,numinteger
            IF (num(j)<min)THEN
                min=num(j)
                pos=j
            END IF
        END DO
        temp=num(i)
        num(i)=min
        num(pos)=temp
    END DO
    PRINT*, " "
    PRINT*, "Sorted Numbers"
    DO i=1, numinteger
    WRITE(*,23,ADVANCE="NO") num
    23 FORMAT (I2)
    END DO   
    END SUBROUTINE

Thanks!


You don't have any spaces between your numbers, but you are also looping over the array, but not incrementing an index... you are asking the computer to print the entire array on each interation.

I think this should be: WRITE(*,23,ADVANCE="NO") num(i)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号