12/13/2022 0 Comments Fortran program for area of circle![]() The exclamation mark mayappear anywhere on a line (except in positions 2-6). ![]() This is highly non-standardin Fortran 77, but is allowed in Fortran 90. You may also encounter Fortran programsthat use the exclamation mark (!) for comments. Commercial Fortran codes oftencontain about 50% comments. Well-written comments are crucial to program readibility. Comments may appear anywhere in the program. CommentsA line that begins with the letter "c" or an asterisk in the first column isa comment. 73-80: Sequence number (optional, rarely used today)Most lines in a Fortran 77 program starts with 6 blanks and ends before column 72, i.e. 6 : Continuation of previous line (optional)Col. ![]() 1 : Blank, or a "c" or "*" for commentsCol. The mostimportant rules are the column position rules: Col. Column position rulesFortran 77 is not a free-format language, but has a very strictset of rules for how the source code should be formatted. The structure of a main program is: program name declarations statements stop endIn this tutorial, words that are in italics should not be taken as literal text, but rather as a generic description.The stop statement is optional and may seem superfluous since the program will stop when it reaches the end anyways, but it is recommended to always terminate a program with the stop statement to emphasize that the execution flow stops there. ![]() Program organizationA Fortran program generally consists of a main program (or driver)and possibly several subprograms (or procedures or subroutines).For now we will assume all the statements are in the main program subprograms will be treated later. Most people now write lower-case since this is more legible,and so will we. write (*,*) 'Give radius r:' read (*,*) r area = 3.14159*r*r write (*,*) 'Area = ', area stop endThe lines that begin with with a "c" are comments and has no purpose other than to make the program more readable for humans.Originally, all Fortran programs had to be written in all upper-caseletters. We start by looking at a simple example: program circle real r, area c This program reads a real number r and printsc the area of a circle with radius r. Fortran 77 BasicsA Fortran program is just a sequence of lines of text.The text has to follow a certain syntax to be a valid Fortranprogram. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |