• No results found

fort13

N/A
N/A
Protected

Academic year: 2020

Share "fort13"

Copied!
27
0
0

Loading.... (view fulltext now)

Full text

(1)

M.Sc 1st year

(2)

Declaration of variables:

We need to tell the computer that the data we are

entering is of real or integer or character type otherwise there may be errors.

For example by default the variables which begin by

letters i to n are considered as integer variable and all other are considered as single precision real variable.

(3)

To solve the problem we use the type statement as

type :: vname1, vname2....

Where type is one of data type we want to use, e.g. Integer, real or character

Suppose we are using i,j,k as real then we write as

Real :: i,j,k

For integer we write

Integer:: i,j,k

Note that the above statements are written in the

(4)

Example :

To avoid the errors always use

implicit none

(5)
(6)

Keep Constant consistent in the program :

We should declare constants in the beginning using Parameter attribute

type : means whether it is real, integer, character name: means name assigned to constant value

(7)

Assignment statements and arithmetic calculations:

General form of assignment statement is:

Above statement calculate the value of expression written on the right side and store that value in the variable name written on the left side. Equal sign is called assignment operator.

Consider expression:

(8)

Operators:

These helps us in performing different computational operations.

Arithmetic operators(+, -, *, /, **)

Relational operators(.eq., .ge., .lt., .le., .ne., .eq.)

(9)

Precedence and Associativity of operators:

Precedence determine the order in which different operators are evaluated.

Associativity determine the order in which the

operators of same precedence are evaluated.

Associativity can be from left to right or right to left

2+5+7

(10)

Arithmetic operators:

3 3 2 2 1

(11)

The five arithmetic operators described above are binary operators means they occur between two operand e.g. a+b, c*d etc

+ and – are also unary operators

e.g. +223, -232

Rules for using arithmetic operators:

No two operators occur side by side

e.g. 2*-4 is not write. We should use 2*(-4)

Implied multiplication is illegal in fortran e.g. We cannot write x(y+z)

We should wrtie x*(y+z)

(12)

Integer Arithmetic: It involve the calculations among integers and always produce integer results.

Be careful while using integers for division. If division of two

integers gives us fractional part then it automatically neglect fractional part.

e.g 9/4 = 2, ¾ = 0 , ½ = 0 etc.

Real Arithmetic: Calculations using reals always give

results in real.

But due to precise nature some time theoretical and calculations using computers gives different results

(13)

Hierarchy of operations:

Suppose we have expression for distance:

How to evaluate: If exponentiation is evaluated first, then Expression will look as

(14)
(15)

Mixed Mode Expression:

It involve the expressions where we have both real and integer

(16)

It is advisable to use real instead of integers to avoid errors in calculations

(17)

Even though in the following expression we expect 3.25 but actually we get the result 3 because the nres in which result has to be stored is an integer.

(18)

Mixed type integer and exponentiation:

As said earlier the mixed mode expression are generally not desirable

But when expressions involve exponentiation then it is

more good to use mixed mode expressions Consider,

Where y, result are real and n is integer

It mean y is multiplied n times with itself

(19)

But suppose we have

where x, y, result are real.

Now let x is suppose 2.5 then it is meaningless to say

that y is multiplied with itself 2.5 times

To evaluate above expression we shall use

But here also y cannot be negative because log of –ve is undefined. We shall get run time error.

(20)
(21)

All relation operators are binary operators and appear

between their operands there is no relative precedence between the relational operators.

In relational operators when real and Integers are

(22)

When we compare two characters the these are evaluated in alphabetical order

Numeric values cannot be compared with

Character. You will get an error.

If there are arithmetic and relation

operators in an expression the first arithmetic

(23)
(24)

Combinational Logical Operators:

(25)
(26)

Hierarchy of operations:

As discussed earlier first we evaluate the arithmetic operators

Relation operators are evaluated working from left to

right

.NOT., operators are evaluated working from left to right

.AND., left to right

OR, left to right

(27)

References

Related documents

Integers worksheet adding two input area, and negative exponent form which operations color by number integer operations worksheets or!. Apply in worksheet by number integer

The second line contains K positive integers where the ith integer represents V [i], the happiness of the ith event.. The third line contains n integers, where the ith

● If the integers have unlike or different signs, divide the integers and put a negative sign to the resulting integer. Let’s have

times as long as the other. b) If k is an integer, all these lengths are integers too. So we have a smaller triangle with integer lengths. Repeating this indefinitely leads to

3) Euler cuboid It is not known whether there exists a cuboid with integer side length such that all face diagonals are integers and additionally, also the large diagonal is an

2 Every integer has a successor as well as predecessor 3 An integer is less than all those integers which lie to its left 4 An integer is greater than all the integers that lie

Puzzle as adding and subtracting integers guided notes with a number line showing integers activity for an original integer addition problems involving tax, the common sense.. Group

Students color worksheet coloring answer to integers adding integer numbers as in problems to color according to new system of this calculator.. Then must exist integers r and s