Question

Fortran questions a) How many input-output statements were there in original Fortran? b) What was...

Fortran questions

a) How many input-output statements were there in original Fortran?

b) What was the largest possible statement number?

c) What was the purpose of statement numbers?

d) In what order would the elements of a 2D array be stored in the object program?

e) What would the “arithmetic formula” statement be called today?

f) If the variable on the left side of an arithmetic formula is a fixed point, and the expression on the right side evaluates to 4.579, what value would be stored in the left side variable

g) writeasingleFORMATstatementtogetherwithasinglePRINTstatementthat together have the same effect as the following call of printf (a C/C++ library function): printf("x = %8.5f i = %5d", x, i);

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1). There were 12 statements

Answer 2). 2147483647

Answer 3).So far we have only showed free format input/output. This uses a set of default rules for how to output values of different types (integers, reals, characters, etc.). Often the programmer wants to specify some particular input or output format, e.g. how many decimals in real numbers. For this purpose Fortran 77 has the format statement. The same format statements are used for both input and output.

Syntax

      write(*, label) list-of-variables
 label format format-code

A simple example demonstrates how this works. Say you have an integer variable you want to print in a field 4 characters wide and a real number you want to print in fixed point notation with 3 decimal places.

      write(*, 900) i, x
  900 format (I4,F8.3)

The format label 900 is chosen somewhat arbitrarily, but it is common practice to number format statements with higher numbers than the control flow labels. After the keyword format follows the format codes enclosed in parenthesis. The code I4 stands for an integer with width four, while F8.3 means that the number should be printed using fixed point notation with field width 8 and 3 decimal places.

The format statement may be located anywhere within the program unit. There are two programming styles: Either the form,at statement follows directly after the read/write statement, or all the format statements are grouped together at the end of the (sub-)program.

Common format codes

The most common format code letters are:

   A - text string
   D - double precision numbers, exponent notation
   E - real numbers, exponent notation
   F - real numbers, fixed point format
   I - integer
   X - horizontal skip (space)
   / - vertical skip (newline)

The format code F (and similarly D, E) has the general form Fw.d where w is an integer constant denoting the field width and d is an integer constant denoting the number of significant digits.

For integers only the field width is specified, so the syntax is Iw. Similarly, character strings can be specified as Aw but the field width is often dropped.

If a number or string does not fill up the entire field width, spaces will be added. Usually the text will be adjusted to the right, but the exact rules vary among the different format codes.

For horizontal spacing, the nX code is often used. This means n horizontal spaces. If n is omitted, n=1 is assumed. For vertical spacing (newlines), use the code /. Each slash corresponds to one newline. Note that each read or write statement by default ends with a newline (here Fortran differs from C).

Some examples

This piece of Fortran code

      x = 0.025
      write(*,100) 'x=', x
  100 format (A,F)
      write(*,110) 'x=', x
  110 format (A,F5.3)
      write(*,120) 'x=', x
  120 format (A,E)
      write(*,130) 'x=', x
  130 format (A,E8.1)

produces the following output when we run it:

x=      0.0250000
x=0.025
x=  0.2500000E-01
x= 0.3E-01

Note how blanks are automatically padded on the left and that the default field width for real numbers is usually 14. We see that Fortran 77 follows the rounding rule that digits 0-4 are rounded downwards while 5-9 is rounded upwards.

In this example each write statement used a different format statement. But it is perfectly fine to use the same format statement from many different write statements. In fact, this is one of the main advantages of using format statements. This feature is handy when you print tables for instance, and want each row to have the same format.

Format strings in read/write statements

Instead of specifying the format code in a separate format statement, one can give the format code in the read/write statement directly. For example, the statement

 
      write (*,'(A, F8.3)') 'The answer is x = ', x

is equivalent to

 
      write (*,990) 'The answer is x = ', x
  990 format (A, F8.3)

Sometimes text strings are given in the format statements, e.g. the following version is also equivalent:

 
      write (*,999) x
  999 format ('The answer is x = ', F8.3)

Implicit loops and repeat counts

Now let us do a more complicated example. Say you have a two-dimensional array of integers and want to print the upper left 5 by 10 submatrix with 10 values each on 5 rows. Here is how:

      do 10 i = 1, 5
         write(*,1000) (a(i,j), j=1,10)
   10 continue
 1000 format (I6)

We have an explicit do loop over the rows and an implicit loop over the column index j.

Often a format statement involves repetition, for example

  950 format (2X, I3, 2X, I3, 2X, I3, 2X, I3)

There is a shorthand notation for this:

  950 format (4(2X, I3))

It is also possible to allow repetition without explicitly stating how many times the format should be repeated. Suppose you have a vector where you want to print the first 50 elements, with ten elements on each line. Here is one way:

      write(*,1010) (x(i), i=1,50)
 1010 format (10I6)

The format statements says ten numbers should be printed. But in the write statement we try to print 50 numbers. So after the ten first numbers have been printed, the same format statement is automatically used for the next ten numbers and so on.

Add a comment
Know the answer?
Add Answer to:
Fortran questions a) How many input-output statements were there in original Fortran? b) What was...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • FORTRAN QUESTIONS: a) How many input-output statements were there in original Fortran? b) What was the...

    FORTRAN QUESTIONS: a) How many input-output statements were there in original Fortran? b) What was the largest possible statement number? c) What was the purpose of statement numbers? d) In what order would the elements of a 2D array be stored in the object program? e) What would the ”arithmetic formula” statement be called today? f) If the variable on the left side of an arithmetic formula is a fixed point, and the expression on the right side evaluates to...

  • Make a program using Java that asks the user to input an integer "size". That integer...

    Make a program using Java that asks the user to input an integer "size". That integer makes and prints out an evenly spaced, size by size 2D array (ex: 7 should make an index of 0-6 for col and rows). The array must be filled with random positive integers less than 100. Then, using recursion, find a "peak" and print out its number and location. (A peak is basically a number that is bigger than all of its "neighbors" (above,...

  • Please help this out with all Purpose: Learn how to get input and print out formatted...

    Please help this out with all Purpose: Learn how to get input and print out formatted results using scanf and printf separately in C. 1) Write a C program getPhone Number:c that accepts a phone number from the user in the form XXX-XXX-XXXX, and then displays it in the form (XXX)XXX-XXXX: Enter a phone (XXX-XXX-XXXX): 011-123-4567 You entered (011) 123-4567 Question: Execute your getPhoneNumber.c and attach a screenshot of the output. Then write the source code of getPhoneNumber.c in your...

  • QUESTION 42 In Matlab, all arrays start at position zero. O True O False QUESTION 43...

    QUESTION 42 In Matlab, all arrays start at position zero. O True O False QUESTION 43 In C, the expression x=2 is used to compare if the value of x is equal to the value of 2, and the expression x==2 is used to assign the value of 2 to x. O True O False QUESTION 44 What is the C and Matlab function used to open an input file? Hint: This is a single word. Spelling and syntax must...

  • What would be the results of the following code? Create array1 ← [33, 88, 11, 44,...

    What would be the results of the following code? Create array1 ← [33, 88, 11, 44, 99, 55] value ← array1[0] FOR each value in array1 IF(array1[i] < value) THEN value ← array1[i] ENDIF ENDFOR Question 7 options: A) Value contains the lowest value in array1. B) Value contains the highest value in array1. C) Value contains the sum of all the values in array1. D) Value contains the average of the values in array1. Question 8 (1 point) What...

  • These are my answere to the following questions: are they right? 1. B 2. T 3....

    These are my answere to the following questions: are they right? 1. B 2. T 3. T 4. T 5. F 6. T 7. A 8. D 9. E 10. B 11. B 12. A 13. A 14. D 15. C 16. D 17. T 18. C 19. T 20. T 21. T 22. A 23. T 24. D 25. B 26. A 27. A 28. A 29. T 30. C 31. D 32. A 33. T 34. F 35....

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • A. What is the time complexity of Insertion Sort? B. Explain why Insertion Sort has the...

    A. What is the time complexity of Insertion Sort? B. Explain why Insertion Sort has the time complexity you listed above in Part A. C. Show the steps followed by the Quicksort algorithm given below in pseudocode when sorting the following array. Algorithm Quicksort (A, left, right) if (left < right) pivot Point + [(left+right)/2] // note central pivot it left - 1 j right + 1 do do iti + 1 while (i < A.size) and (A[i] = A[pivotPoint])...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) L...

    C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT