This is about fortran, can you please find any errors over here? •Each variable
ID: 668134 • Letter: T
Question
This is about fortran, can you please find any errors over here?
•Each variable must be named.
•A variable name must start with a letter, followed by letters, digits, or an underscore (“_”) and may not be longer than 32 characters. Capital letters are treated the same way as lower-case letters, (case insensitive: i.e., “AAA” is the same variable as “aaa”).
•For example, some valid variable names are as follows: x, today, next_month, summation1,
•Some invalid examples include: 1today, A_variable_name_with_too_many_characters, next@month, next month, today!
•Note that the space (between next and month) at the special character, @, that is not allowed.
•A logical variable is only allowed to have two values, true or false. A logical value may also be referred to as a boolean.
•In Fortran, the true and false values are formally expressed as .true. or .false. which are also called logical constants.
•The leading and trailing “.” (periods) are required for true and false constants.
•Implicit typing: the type of a variable depends on the first letter of its name unless a variable was explicitly typed (i.e. declared on that type).
•Thus, if not explicitly declared, a variable whose name started with one of the letters I through O was assumed to be an integer; otherwise it was assumed to be real.
•Older versions of Fortran assumed implicit typing.
•To allow older code to run, Fortran 95 permits implicit typing.
•However, this is poor practice, can be confusing, and often leads to errors. So, we will include the IMPLICIT NONE statement at the start of all programs. This turns off implicit typing and the compiler will identify and flag any variable not defined.
•Declaring variables formally defines the data type of each variable and sets aside a memory location. This is performed by a type declaration statement in the form of:
<type> :: <list of variable names>
•Examples:
integer :: today, tomorrow, yesterday
real :: ans2
complex :: z
logical :: answer
•Comma is used to separate multiple variable declarations on the same line.
•The declarations can be entered in any order.
•A statement must start on a new line. If a statement is too long to fit on a line (over 80 characters in length), it can be continued on the next line with an ampersand ('&'). Even shorter lines can be split and continued on multiple lines for a more readable formatting.
•For example,
A = 174.5 * year &
+ count / 100.0
is equivalent to the following
A = 174.5 * year + count / 100.0
•Note that the '&' is not part of the statement.
Explanation / Answer
•Each variable must be named.
TRUE...without namimg we cannot reference that variable
----------------------------------------------------------------------------
•A variable name must start with a letter, followed by letters, digits, or an underscore (“_”)
and may not be longer than 32 characters. Capital letters are treated the same way as lower-case letters,
(case insensitive: i.e., “AAA” is the same variable as “aaa”).
TRUE
--------------------------------------------------------------------------------------------------
•For example, some valid variable names are as follows: x, today, next_month, summation1, -->TRUE
------------------------------------------------------------------------------------------------------------
•Some invalid examples include: 1today, A_variable_name_with_too_many_characters, next@month, next month, today! -->TRUE
--------------------------------------------------------------------------------------------------
•Note that the space (between next and month) at the special character, @, that is not allowed. ---->
space not allowed for variables ..if space given it treats as new variable --->TRUE
----------------------------------------------------------------------------------------------------------
•A logical variable is only allowed to have two values, true or false. A logical value may also be referred to as a boolean.
yes...true/false or 0/1
----------------------------------------------------------------------------------------------------------------------
•In Fortran, the true and false values are formally expressed as .true. or .false. which are also called logical constants.
yes boolean values
-----------------------------------------------------------------------------------------------
•The leading and trailing “.” (periods) are required for true and false constants. ->yes ==>EG: tf = .true.
--------------------------------------------------------------------------------------------------------------
•Implicit typing: the type of a variable depends on the first letter of its name unless a variable was explicitly typed
(i.e. declared on that type).
•Thus, if not explicitly declared, a variable whose name started with one of the letters I through O was assumed to be an integer; otherwise it was assumed to be real.
•Older versions of Fortran assumed implicit typing.
•To allow older code to run, Fortran 95 permits implicit typing.
•However, this is poor practice, can be confusing, and often leads to errors. So, we will include the IMPLICIT NONE statement at the start of all programs.
This turns off implicit typing and the compiler will identify and flag any variable not defined
----> This statements are valid for python ruby even more too....I dont think these are confusin..compiler will handle about
data types. we will have any confuse at any point in the program.
---------------------------------------------------------------------------------------------------------------------
Declaring variables formally defines the data type of each variable and sets aside a memory location. This is performed by a type declaration statement in the form of:
<type> :: <list of variable names>
•Examples:
integer :: today, tomorrow, yesterday
real :: ans2
complex :: z
logical :: answer
•Comma is used to separate multiple variable declarations on the same line.
•The declarations can be entered in any order.
•A statement must start on a new line. If a statement is too long to fit on a line (over 80 characters in length), it can be continued on the next line with an ampersand ('&'). Even shorter lines can be split and continued on multiple lines for a more readable formatting.
•For example,
A = 174.5 * year &
+ count / 100.0
is equivalent to the following
A = 174.5 * year + count / 100.0
•Note that the '&' is not part of the statement.
=======> VALID
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.