Question: Code in fortran There is a file called mat2.txt in our CatCourses files area under the Assignments folder. Download it and save it in the
Code in fortran
There is a file called mat2.txt in our CatCourses files area under the Assignments folder. Download it and save it in the same folder where this Fortran file (HW04_02.f95) is saved. It maybe worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Fortran program that does the following:
Declares a string variable (suggested length: at least 80 characters) to hold the input file name. Prompt the user for an input file name and read the user's input to your string variable. Declare a two-dimensional dynamic integer array.Hint:dimension(:,:), allocatable will be handy.
Open the file name the user has entered for reading and read the first line to see how many lines and columns it has. Use that information to allocate your dynamic array. Use a loop to read the rest of the input file into your array. Close the input file. Use a separate loop to print the array to the console in a neat table. Noting that none of the numbers in the input file is larger than 99, choose an output format that results in a neat table with no more than 4 spaces before each number.*
Do not assume that the input file has a fixed number of rows or columns. Assume that that information is on the first line of the file and that your program will read it. Your program may be tested with adifferent file with a different number of rows and columns and it should work without modification.
Note that this will require some thought, since the number of columns can change and your code must adjust for that at runtime. There are several different ways to do this. Among them are creating the format string dynamically or using a nested loop to print one column at a time on an output line, using advance="no" in the write statement to keep printing on one line until you are done with it.
File for Mat2.txt
10, 5
75, 82, 48, 49, 95
74, 69, 44, 95, 54
39, 31, 64, 34, 13
65, 95, 70, 58, 14
17, 3, 75, 22, 25
70, 43, 27, 75, 84
3, 38, 67, 25, 25
27, 76, 65, 50, 81
4, 79, 16, 69, 24
9, 18, 11, 89, 92
.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
