Friday 30 January 2015

55 TOP Fortran Interview Questions and Answers

1. How should one spell FORTRAN/Fortran? 
FORTRAN is generally the preferred spelling for discussions of versions of the language prior to the current one (‘90”). Fortran is the spelling chosen by X3J3 and WG5. In this document a feeble effort has been made to capitalize accordingly (e.g. vast existing software ... FORTRAN vs. generic Fortran to mean all versions of the standard, and specifically the modern dialect, ISO
1539:1991).

2. how does Fortran 90 relate to FORTRAN 77? 
With a few minor exceptions, Fortran 90 is a superset of X3.9-1978 FORTRAN.
But this does not mean that all ‘77” codes will port sans changes. Many (if not most) programmers employed constructs beyond the ‘77 standard, or rely on unspecified behavior (say, assuming that an OPEN of an existing file will position the file pointer to just past the last record already written) which has changed (that is to say, has become specified).

3. Why do you put so many lines of empty space in your programs? 
I hope the lines aren’t totally empty. They should contain a “c” in column one. These “blank” lines are just to make the comments stand out from Fortran code lines or to highlight key blocks of a program.

4. how do you use a logical variable? What is stored there? 
Most frequently, logical variables are used in association with IF statements. When you want to
set a logical variable LVAR to true you use “LVAR=.TRUE.”. For false use “LVAR=.FALSE.”
In practice the computer usually stores an integer( ) in memory for false and integer 1 for true.
The normal logical variable occupies 1 byte of space.

5. where can i get a Fortran Compiler for IBM PC? 
We can pick up one on the internet from the GNU project, but get a better package from MOC for about S80.00.

6. how do we know where various steps go in a Fortran program? 
Some commands have special locations, but most are located by the needs of the specific program. The PROGRAM card is always first Statements giving variable types (INTEGER, REAL, LOGICAL, CHARACTER) should precede “executable” statements. The END card must always be at the end of the program unit.

7. Why does not Fortran have intrinsic functions for something as simple as factorial? 
Two reasons. Factorial isn’t all that common in heavy duty scientific and engineering applications. When it does occur, it almost always in a context where it is more computationally efficient to generate it as you go. You need 2? first then 3!, then 4!, etc. You are basically stuck doing a factorial within the context of a do loop unless you get really good and learn to write “recursive functions”, but then you arejust fooling yourself and writing another form of do loop. When you are taking the factorial of a large number and don’t need an exact answer you can resort to Stirling’s Approximation. A Fortran statement that will load the value of this approximation into the variable nfact is.

8. What is the advantage of an array over a spreadsheet format? 
Both can store similar types of information m a neatly labeled and organized way. The advantage lies in where they are used. You have more control over how Fortran arrays are used than how the contents of a spreadsheet are used. In addition for any given operation on an array of numbers, once the Fortran is written, it will do the job much faster than a spreadsheet. On the other hand, when operations are not complex and computer execution time is not a problem using the spreadsheet is probably your best bet.

9. Do spaces mater in Fortran equations? 
No. Spaces are generally added for clarity Some compilers get upset if you write things like”
INTEGERI,J” rather than INTEGER I,J”. Simple neatness will keep you out of these problems.
Remember that a space is required in column 6 if you aren’t continuing from the previous line.
The following are all equivalent:
x=x*y**2*sin(x)
x=x * y2 * sin(x)
x= x * y**2 * sin ( x)

10. Why doesn't Fortran have intrinsic functions for something as simple as factorial? 
Two reasons. Factorial isn't all that common in heavy duty scientific and engineering applications. When it does occur, it almost always in a context where it is more computationally efficient to generate it as you go. You need 2! first then 3!, then 4!, etc. You are basically stuck doing a factorial within the context of a do loop unless you get really good and learn to write "recursive functions", but then you are just fooling yourself and writing another form of do loop. When you are taking the factorial of a large number and don't need an exact answer you can resort to Stirling's Approximation. A Fortran statement that will load the value of this approximation into the variable fact.
More Questions & Answers :-
Part1  Part2  Part3  Part4  Part5  Part6

No comments:

Post a Comment