Next: About this document ...
Up: Multidimensional Arrays
Previous: Array Trickery

Checkoff

As long as you aren't trying to do trickery along the lines discussed in the previous section (or trying to initialize an array with a DATA statement) you can visualize the organization of a multi-dimensional array any way you want. You don't have to worry about how Fortran represents the array in memory.

Prove this to yourself by rewriting ``marray2.f'' as follows. Currently, the first dimension of the array corresponds to the vertical dimension of the table, the second dimension of the array corresponds to the horizontal dimension of the table, and the third dimension of the array corresponds to one of the three tables actually stored in the array.

Change it so that the first dimension corresponds to the tables, the second dimension corresponds to the vertical dimension, and the third dimension corresponds to the horizontal dimension. Your resulting program should behave just like ``marray2.f''.

Homework Problem 11

This is the final homework problem. You will have until the last Wednesday of the quarter to complete it. It is a long one, so get started early.

Write a program that can multiply non-negative integers that can be up to 48 digits long.

Your program should ask the user to enter the name of the input file. The first line of the input file is the length of the first number and the second line is the first number, which can be up to 48 digits in length. Your program should read the number in as a sequence of individual one-digit integers, since a 50 digit integer is too long to deal with directly. You should store each digit in an array location. For example, if you read in the number 1234567, your array should look like:

         ______________________________________
          |   |   |   |   |   |   |   |   |   |
     ...  | 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
         _|___|___|___|___|___|___|___|___|___|

Your program should read the length of the second number and then the second number from the input file, which can also be up to 48 digits.

Your program should then multiply the two numbers using the multiplication algorithm that you learned in the third grade, producing a second array containing the product. Note that the product might be as long as 96 digits long.

Finally, your program should print out the product to the output file called "output". You'll have to print out the number digit by digit. You also have to remove any leading 0's. When there is a error in the file, report it and exit the program.

Here is a sample input file.

32
12345678901234567890098765432145
15
876543214876395

Here is a sample run.

Enter the name of the input file:
input.dat

Hint: You should first write subroutines that allow you to read in and write out long integers stored in arrays as described above. Next, you will need to write a subroutine to do addition of long integers. Only then should you worry about multiplication. If you don't develop, test, and debug your subroutines one at a time, you will be unlikely to finish this problem.

Call your program solution11.f. To submit it for grading, use the UNIX Shell window to connect to the directory that contains your program and enter the following command

hand-in cs101 problem-11 solution11.f


Next: About this document ...
Up: Multidimensional Arrays
Previous: Array Trickery

Hamlet Project
hamlet@cs.utah.edu