Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fortran 90 array/subroutine problem

Status
Not open for further replies.

danielp1213

Programmer
Nov 2, 2011
2
CA
Hey guys I was wondering if i could get some help with my program. I am trying to add 2 separate arrays together section by section to create a large integer. I have a bunch of the code finished but I am having trouble with the sub routine and how it works. Here is the question:

Write a Fortran program to operate on two large integers (of any length, say,
up to 300 digits) and a subroutine to perform their addition.
(a) A suggested approach is as follows: Treat each number as a list (onedimensional
array) each of whose elements is a block of digits of that
number. For example, the integer 179,534,672,198 might be stored with
N(1) = 179,N(2) = 534,N(3) = 672,N(4) = 198.
(b) Then add the two integers (lists) element by element, carrying from one
element to the next when necessary.
(c) Test your subroutine by a program that reads two large integers and calls
the subroutine to find and output their sum.

and here is the code so far:

PROGRAM largeint
IMPLICIT NONE
CHARACTER (len=10) :: NUMx, NUMy
INTEGER :: i

OPEN (UNIT=1, FILE='int2.dat', STATUS='OLD')

READ(1,*) NUMx
READ(1,*) intx(i) i=1,3

READ(1,*) NUMy
READ(1,*) inty(i) i=1,3


CONTAINS
SUBROUTINE sumint(intx, inty)
INTEGER,INTENT(IN) :: intx, inty
INTEGER :: carry, i, z
z = intx + inty
carry = 0
DO i=1,3
L = 3-i+1
z(L) = z(L) + carry
carry=0
IF (z(L)>1000) THEN
z(L) = z(L) -1000
carry=1
END IF
END DO
END SUBROUTINE sumint


END PROGRAM largeint

sorry for the post being so long but not sure else how to put it. Thanks for any help you can offer!
 
I get several errors dealing with the intx and inty array and also with z in the function.
I get an error with declaring the variable or something.
 
You have IMPLICIT NONE, but you didn't declare INTX and INTY in the main program.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top