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

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

1 Chapter 2 Basic Elements of Fortran Programming.
ALGEBRA 1 BASICS CHEAT SHEET THINGS YOU SHOULD KNOW . . .
Introduction to C Programming
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
10 November JavaScript. Presentation Hints What do YOU think makes a good presentation Some of my suggestions Don’t write full sentences on slides Talk,
Chapter 2 Basic Elements of Fortan
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Python November 14, Unit 7. Python Hello world, in class.
LAB-05 Function I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
ICS 103 Lab 2-Arithmetic Expressions. Lab Objectives Learn different arithmetic operators Learn different arithmetic operators Learn how to use arithmetic.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Introduction to C Programming
LAB-03 Logical Operations I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum.
LAB-12 2-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
1 Chapter 2: Data Types & Operations Part 3 ICS101: Computer Programming Al-Hashim, Amin G.
LAB-10 1-D Array I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
CHAPTER 3: CORE PROGRAMMING ELEMENTS Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
Basic Elements of C++ Chapter 2.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
Section 1.1 Numbers and Their Properties.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Fall, 2006Introduction to FORTRAN1 (2 + 2 = ???) Numbers, Arithmetic Nathan Friedman Fall, 2006.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
1 CSC103: Introduction to Computer and Programming Lecture No 6.
Input, Output, and Processing
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
C++ Programming: Basic Elements of C++.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
CPS120: Introduction to Computer Science Operations Lecture 9.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Chapter 7 Expressions and Assignment Statements. Outline Introduction Arithmetic Expressions Overloaded Operators Type Conversions Assignment Statements.
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
Topic 4 Real Numbers Rational Numbers To express a fraction as a decimal, divide the numerator by the denominator.
COMP Primitive and Class Types Yi Hong May 14, 2015.
Lecture III Start programming in Fortran Yi Lin Jan 11, 2007.
Introduction to Exponents Definition: Let b represent a real number and n a positive integer. Then … b is called the base and n is called the exponent.
D-1 University of Washington Computer Programming I Lecture 4: Arithmetic Expressions © 2000 UW CSE.
 Constants A constant is a fixed value of a data type that cannot be changed Integer Constants Whole numbers → Do not have decimal points Examples: 83.
LAB-09 DO WHILE loop I Putu Danu Raharja Information & Computer Science Department CCSE - King Fahd University of Petroleum & Minerals.
C-1 9/30/99 CSE / ENGR 142 Programming I Arithmetic Expressions © 1999 UW CSE.
ICS102 Lecture 1 : Expressions and Assignment King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer.
Chapter 02 (Part II) Introduction to C++ Programming.
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
CSE 220 – C Programming Expressions.
Topics Designing a Program Input, Processing, and Output
BASIC ELEMENTS OF A COMPUTER PROGRAM
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Arithmetic Operator Operation Example + addition x + y
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
LAB-06 IF + Functions I Putu Danu Raharja
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Primitive Types and Expressions
DATA TYPES AND OPERATIONS
ICS 101 Lab 3 Hossain Arif ICS Dept
Presentation transcript:

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

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

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

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

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

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.

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.

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.

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: How old are you? 18 Muhammad Ali (223344) is 18 years old.

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

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

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 – * 3 / 4 2 / 3 * 42 ** 3 ** 2

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

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

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

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

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.