Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University.

Similar presentations


Presentation on theme: "1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University."— Presentation transcript:

1 1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja raharja@ kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals

2 Data Type What are data types? What are the differences among them? Range of values Result of operation Data types in Fortran 77 Integer Real Logical Character We can use explicit or implicit definition Explicit definition is recommended

3 Integer What is it? Examples? No decimal point 32 bit Integer (-2147483648 to +2147483647) Implicit definition starts with: I, J, K, L, M, N Remember: Explicit definition is recommend-ed.

4 Real Real numbers (Examples?) With decimal point or scientific notation 3.1415 -9.8 0.76E-16 Implicit definition starts with any characters other than I – N. Remember (again): Explicit definition is recommended.

5 Character To store characters Text/String: chain of characters CHARACTER SPEED*20 CHARACTER*7 FIRST, MIDDLE*3, LAST CHARACTER TEST

6 Simple Output Statement PRINT statement shows a text, values of variables or results of operations to the output device such as screen. A text must be enclosed by quotes Single or double quotes can be used but be sure to end the text with the same type of quote.

7 Exercise-1 Write a program to display the following text: In this course, you will be introduced to the basic concepts of computing and computer programming. It's an exciting experience.

8 Simple Input Statement To read an input value from terminal into a variable. Each unformatted READ* statement starts reading from a new line. The data values must agree in type with the variables. The data values can be separated by blanks or comma.

9 Exercise-2 Write a program that asks your name, your student ID, and your age and then displays the inputs as follows: Your Name: Muhammad Ali Your student ID: 223344 How old are you? 18 Muhammad Ali (223344) is 18 years old.

10 Arithmetic Operations See page 13 Operator & operand Binary & unary operators Basic operators: Exponentiation: ** Multiplication: * Division: / Addition: + Substraction: -

11 Precedence 1. Parentheses 2. Exponentiation 3. Multiplication & Division 4. Addition & Substraction What is the result of the following expresions: 2 + 3 * 4(2 + 3) * 4 3 * 2 ** 3(3 * 2) ** 34 ** 0.5 1/31/3.03 / 5 * 10

12 Associativity What are these: Commutative, Associative, Distributive? How is it to evaluate operators with same precedence? Exponentiation: right to left Others: left to right What is the result of the following expressions: 4 – 2 + 52 * 3 / 4 2 / 3 * 42 ** 3 ** 2

13 Notes We can not write two operators consecutively such as: 2 * -3 It must be written as 2 * (-3) We cannot raise a negative number to a real exponent in Fortran 77 Why? x y = e y ln x is used for real exponent (-2) ** 0.5 ? (-1) ** (1.0 / 3) ? Multiplication is “cheaper” than exponentiation

14 Integer, Real, or Mixed Operation? Integer operands: integer result 1/3 → 0 Real operands: real result 1.0/3.0 → 0.33333... Integer & real operands: real results 1.0/3 → 0.333333...

15 Notes Remember (again): readability Parentheses are very useful Watch for incomplete ones Is it complete?: 1 * (a / (b – (c * 5))) Keep each expression readable However, in Major-I usually you will be asked to used least number of parentheses

16 Assignment Assignment: assigning a value to a variable Assignment ≠ Mathematical equation X = 5 means we assign the value of 5 into X; it doesn't say that X equals to 5

17 Exercises-3 Write a program to take as input the radius of a circle; compute and display its area and circumference. Write a program that computes the speed of sound A (ft/s) in air of a given temperature T (°F). Use the formula Write a program to take as input the length of each side of a triangle; compute and display its area.


Download ppt "1 ICS 101 – LAB 2 Arithmetic Operations I Putu Danu Raharja kfupm.edu.sa Information & Computer Science Department CCSE - King Fahd University."

Similar presentations


Ads by Google