2. Basic Elements of Fortran

Size: px
Start display at page:

Download "2. Basic Elements of Fortran"

Transcription

1 2. Basic Elements of Fortran

2 Structure of a Fortran Program 31 characters must be in the 1st line if present declaration section program my_first_program! Declare variables integer :: i, j, k! i, j, k are integer execution section! Interactive input write(*,*) 'Enter the numbers' read(*,*) i, j! Multiply the numbers k = i*j! Interactive output write(*,*) 'i*j = ', k comment after exclamation point termination section stop end program (optional) stop running program, present before end program tell compiler no more statement

3 Goto the folder \GNU_emacs_Fortran Click CMD_emacs_Fortran.bat to open command prompt console and Emacs editor >dir >mkdir examples >cd examples In Emacs editor, create a new file named 2-2.f90 in the folder \examples Copy the program from course webpage and paste on the Emacs editor, and save it. >gfortran 2-2.f90 >dir >a.exe Enter the numbers 2 4 i*j = 8 >a.exe Enter the numbers 2. At line 7 of file 2-2.f90 (unit = 5, file = 'stdin') Fortran runtime error: Bad integer for item 1 in list input

4 Fortran Character Set A ~ Z (uppercase) 26 a ~ z (lowercase) 26 0 ~ 9 (numbers) 10 _ (underscore) * / ** (arithmetic symbols) 5 ( ). =, ' $ :! " % & ; < >? blank (miscellaneous symbols) 17 Total 86 characters can be used in Fortran 95 Upper case and lowercase letters are equivalent in Fortran, i.e. Fortran is case insensitive. But C++ and Java are case sensitive, i.e., A and a are different characters.

5 Fortran Statement Executable statement Non-executable statement : provide information necessary for the proper operation of the program Free-source form statement (90/95/2003) Fixed-source form statement (77 and earlier version) But backward compatible, i.e., you can use fixed-source form in 90/95, but cannot use free-source form in 77.

6 Free-source form statement statement number which gives name of a statement to refer to (1~99999) 12 x = y+z! summation of x and y 12 x = y & +z 132 characters continuation indicator 12 x = y & & +z 40 lines 12 x = y & +z syntax error

7 Fixed-source form statement Do not use!! Just to show you in case your professor is still using Fortran 77. statement label column continuation indicator column instructions column card identification field x = y + z 1 2 x = y 1 + Z A Hollerith card that, when punched, will contain one Fortran statement.

8 Fortran coding sheet Punching machine Card reader What computer (IBM 704) looked like when Fortran was introduced.

9 Constants and Variables legal variables: Time z I_LOVE_you 31 characters; legal characters: a~z, A~Z, 0~9, _ illegal variables: This_is_a_too_long_variable_name (too many characters) 3days (cannot begin with a digit) money$ (cannot use $) Fortran has 5 intrinsic (built-in) types of constants and variables: integer real complex character logical

10 Integer Constant legal integer constants: illegal integer constants: ,357,076 Real Constant legal real constants: illegal real constants: E-3 (=1 x 10-3 ) 124.8E20 (=1.248 x ) 0.15E+1 1,000, E3 10.E1.5

11 A real or floating-point data : E-3 (=1.0 x 10-3 ) 124.8E20 (=1.248 x ) 0.15E+1 A real or floating-point data is stored in a type of scientific notation of base 2 system consisted of two parts, the mantissa and the exponent: mantissa : precision (number of significant digits) exponent : range ( 浮點數 尾數 ) value = mantissa 2 exponent The precision and range of a real value are determined by number of bits allocated. Single-precision real number occupies 32 bits (4 bytes) of memory: 24 bits mantissa: ±2 23 = 8,388,608, i.e., about 6 or 7 significant digits 8 bits exponent: ±2 7 = 128, , i.e., range about ~ Double-precision real number OCCUPIES 64 bits (8 bytes): 53 bits mantissa: ± , i.e., about 14 or 15 significant digits 11 bits exponent: ±2 10 = 1024, , i.e., range about ~

12 computer old Intel 32-bit PC (Pentium) current Intel 64-bit PC declared as double precision Cray (supercomputer) bits per default real number bits in mantissa precision in decimal digits bits in exponent range in exponent ~ ~ ~ ~

13 Character Constants legal character constants: 'This is a test' "This is a test" " " "Dog is man's best friend" '"Who cares? "' illegal constants: 'This is a test" 'This is a test'' Logical Constants (Logical constants are rarely used).true..false.

14 Default and Explicit Variables Typing Default (not specified): (i,j,k,l,m,n) + other characters are integer variables num i38 Others are real variables vel q2 The type of a variables can also be explicitly declared by type declaration statements. integer :: var1, var2, var3 real :: var4, var5 logical :: var6 complex :: var7, var8 optional, but is preferable Character variables must be declared by: optional character(len=10) :: var1, var2 character(15) :: var3

15 Assignment Statements and Arithmetic Calculations Assignment Statements variable = arithmetic expression store the value of expression into the variable location i = i+1 If original i is 3, after the assignment statement i is 4 Arithmetic Operators: + - * / ** wrong operation a*-b a**-2 a*(-b) a**(-2) 2**((8+2)/5) = 2**(10/5) = 2**2 = 4

16 Integer Arithmetic i = 3/4 0 is assigned to i 4/4 1 5/4 1 6/4 1 7/4 1 8/4 2 9/4 2 Real Arithmetic (or floating-point arithmetic) x = 3./ / (precision depends on computers) On some computer, 3.*(1./3.) 1 but 2.*(1./2.) = 1

17 Hierarchy of Operators (order of arithmetic operators) same as the rules of algebra distance = 0.5*accel*time**2 = 0.5*accel*(time**2) (0.5*accel*time)**2 a*b+c*d+e/f**g = (a*b)+(c*d)+(e/(f**g)) a*(b+c)*d+(e/f)**g = (a*(b+c)*d)+(e/f)**g a*(b+c)*(d+e)/f**g = ((a*(b+c))*(d+e))/(f**g) a**b**c = a**(b**c) (a**b)**c = 4 9 = = 4096

18 Mixed-mode arithmetic (Do NOT use whenever possible) The computer converts the integers into real numbers, and real arithmetic is used. 3/2 1 3./ / / integer (= 0) 1+1/ / / real (=0.25) Mixed-mode exponentiation var = y**n = y*y*y*...*y (This, however, is preferable!) But n times var = y**x = e**(x*log(y)) (-2.0)**2 4 (-2.0)**2.0 some compiler will result in runtime error

19 Intrinsic Functions (some) Function name & argument Argument type Result type sqrt(x) SQRT(X) (x 0) R R abs(x) R/I R/I sin(x) (x in radians) R R cos(x) (x in radians) R R tan(x) (x in radians) R R exp(x) R R alog(x) R R alog10(x) R R int(x) integer part of x R I nint(x) nearest integer to x R I real(i) I R fraction(x) = x-int(x) R R mod(a,b) = a-int(a/b)*b remainder R/I R/I max(a,b) R/I R/I min(a,b) R/I R/I asin(x) R R acos(x) R R atan(x) R R

20 PROGRAM my_first_program! Purpose:! To illustrate some of the basic features of a Fortran program.! Declare the variables used in this program. INTEGER :: i, j, k! All variables are integers! Get the variables to multiply together. WRITE(*,*) 'Enter the numbers to multiply: ' READ(*,*) i, j! Multiply the numbers together. k = i * j! Write out the result. WRITE(*,*) 'Result = ', k! Finish up. STOP END PROGRAM

21 List-directed Input and Output read (io_unit, statement_no_format) write(io_unit, statement_no_format) * means to read from standard input device * means free-format input (or list-directed input) The types of the variables in the input variable list determine the required format of the input data. read(*,*) i, j read(*,*) k, l begin to read another line of data write(*,*) " Output: ", i, j, k, l > 1, 2, 3, 4 > 5, 6, 7 > Output: input in console output in console

22 Initialization of Variables 3 ways to initialize a variable: integer :: i i = 1 integer :: i read(*,*) i integer :: i = 1 real :: pi pi = acos(-1.) real :: pi read(*,*) pi real :: pi = acos(-1.) To get the initialized variable as a constant throughout the program, use named constant as: real, parameter :: pi = acos(-1.) real, parameter :: pi = acos(-1.) pi = 3.14 real, parameter :: pi = 3.14 pi = acos(-1.) These are not allowed since pi has been assigned as a constant parameter.

23 IMPLICIT NONE Statement Disable the default typing provisions of Fortran. If you use implicit none statement, you must explicitly declare EVERY variable in the program otherwise it is considered as an error. Good reasons to use implicit none statement: catch typos at compilation time, and make the code more manageable program test_1 real :: time =10.0 write (*,*) 'Time = ', tmie end program test_1 Program test_1 will be compiled successfully, and produce output: Time = E+00. program test_2 implicit none real :: time =10.0 write (*,*) 'Time = ', tmie end program test_2 In contrast, program test_2 will be compiled with error!

24 Program Example: 5 T t Convert temperature T F in degrees of Fahrenheit ( F) to an absolute 9 temperature t k in Kelvin (K). T F = 5 9 t k program temp_conversion! Purpose: To convert an input temperature from degrees! Fahrenheit to an output temperature in kelvins. implicit none! Force explicit declaration of variables! Declare variables, and define each variables when it is declared real :: temp_f! Temperature in degrees Fahrenheit real :: temp_k! Temperature in kelvins! Prompt the user for the input temperature. write(*,*) 'Enter the temperature in degrees Fahrenheit: ' read (*,*) temp_f! Convert to kelvins. temp_k = (5./9.)*(temp_f-32.) ! Write out the result. write(*,*) temp_f, ' degrees Fahrenheit = ', temp_k, ' kelvins '! Finish up. end program

25 In Emacs editor, create a new file named 2-6.f90 in the folder \examples Copy the program from course webpage and paste on the Emacs editor, and save it. >gfortran 2-6.f90 >dir >a.exe Enter the temperature in degrees Fahrenheit: degrees Fahrenheit = kelvins > >gfortran 2-6.f90 -o 2-6.out >dir >2-6.out Enter the temperature in degrees Fahrenheit: degrees Fahrenheit = kelvins >

26 Exercise 1 Write a Fortran program which prompts to input your name (in English) and ID as in the example program, and output as follow: My name is your name. My student ID is your id. Exercise 2 Write a Fortran program to compute the area of a triangle determined by jointing the three points (x1,y1), (x2,y2) and (x3,y3) given by a user who executes the program. Use implicit none statement in your program. Exercise 3 Write a Fortran program to computer the logarithm of a number x to an arbitrary base b, i.e., log b x, using the intrinsic function ALOG10(x). Test the program by calculating the logarithm to the base e of number x using ALOG(x). Use implicit none statement in your program.

27

Goals for This Lecture:

Goals for This Lecture: Goals for This Lecture: Understand integer arithmetic Understand mixed-mode arithmetic Understand the hierarchy of arithmetic operations Introduce the use of intrinsic functions Real Arithmetic Valid expressions

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

Data Types and Basic Calculation

Data Types and Basic Calculation Data Types and Basic Calculation Intrinsic Data Types Fortran supports five intrinsic data types: 1. INTEGER for exact whole numbers e.g., 1, 100, 534, -18, -654321, etc. 2. REAL for approximate, fractional

More information

Chapter 2. Outline. Simple C++ Programs

Chapter 2. Outline. Simple C++ Programs Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

More information

2 Making Decisions. Store the value 3 in memory location y

2 Making Decisions. Store the value 3 in memory location y 2.1 Aims 2 Making Decisions By the end of this worksheet, you will be able to: Do arithmetic Start to use FORTRAN intrinsic functions Begin to understand program flow and logic Know how to test for zero

More information

Our Strategy for Learning Fortran 90

Our Strategy for Learning Fortran 90 Our Strategy for Learning Fortran 90 We want to consider some computational problems which build in complexity. evaluating an integral solving nonlinear equations vector/matrix operations fitting data

More information

Fortran 90 Basics. Fall I don t know what the programming language of the year 2000 will look like, but I know it will be called FORTRAN.

Fortran 90 Basics. Fall I don t know what the programming language of the year 2000 will look like, but I know it will be called FORTRAN. Fortran 90 Basics I don t know what the programming language of the year 2000 will look like, but I know it will be called FORTRAN. Fall 2009 Charles Anthony Richard Hoare 1 F90 Program Structure A Fortran

More information

Program Structure and Format

Program Structure and Format Program Structure and Format PROGRAM program-name IMPLICIT NONE specification part execution part subprogram part END PROGRAM program-name Comments Comments should be used liberally to improve readability.

More information

An Introduction to Unix

An Introduction to Unix An Introduction to Unix Sylvia Plöckinger March 3, 2011 Sylvia Plöckinger () An Introduction to Unix March 3, 2011 1 / 29 General Information Find this file on: http://homepage.univie.ac.at/nigel.mitchell/numprac/

More information

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Methods CSC 121 Fall 2014 Howard Rosenthal

Methods CSC 121 Fall 2014 Howard Rosenthal Methods CSC 121 Fall 2014 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class Learn the syntax of method construction Learn both void methods and methods that

More information

1.1 Numbers system :-

1.1 Numbers system :- 1.1 Numbers system :- 1.3.1 Decimal System (0-9) :- Decimal system is a way of writing numbers. Any number, from huge quantities to tiny fractions, can be written in the decimal system using only the ten

More information

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double

ME 172. Lecture 2. Data Types and Modifier 3/7/2011. variables scanf() printf() Basic data types are. Modifiers. char int float double ME 172 Lecture 2 variables scanf() printf() 07/03/2011 ME 172 1 Data Types and Modifier Basic data types are char int float double Modifiers signed unsigned short Long 07/03/2011 ME 172 2 1 Data Types

More information

Introduction to Computational Modeling

Introduction to Computational Modeling Introduction to Computational Modeling Lecture 1 : Introduction to UNIX and Fortran Instructor : Cedric Weber Course : 4CCP1000 General informations Ø Lecture: Thursday, 9-10am Ø Practice: K3.16 (25C),

More information

3.1. Chapter 3: The cin Object. Expressions and Interactivity

3.1. Chapter 3: The cin Object. Expressions and Interactivity Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 3-1 The cin Object Standard input stream object, normally the keyboard,

More information

The Number object. to set specific number types (like integer, short, In JavaScript all numbers are 64bit floating point

The Number object. to set specific number types (like integer, short, In JavaScript all numbers are 64bit floating point Internet t Software Technologies JavaScript part three IMCNE A.A. 2008/09 Gabriele Cecchetti The Number object The JavaScript Number object does not allow you to set specific number types (like integer,

More information

AMS 27L LAB #1 Winter 2009

AMS 27L LAB #1 Winter 2009 AMS 27L LAB #1 Winter 2009 Introduction to MATLAB Objectives: 1. To introduce the use of the MATLAB software package 2. To learn elementary mathematics in MATLAB Getting Started: Log onto your machine

More information

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB: Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...

More information

CEN 414 Java Programming

CEN 414 Java Programming CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name]

FORTRAN Basis. PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] PROGRAM LAYOUT PROGRAM program name IMPLICIT NONE [declaration statements] [executable statements] END PROGRAM [program name] Content in [] is optional. Example:- PROGRAM FIRST_PROGRAM IMPLICIT NONE PRINT*,

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language

More information

1 Week 1: Basics of scientific programming I

1 Week 1: Basics of scientific programming I MTH739N/P/U: Topics in Scientific Computing Autumn 2016 1 Week 1: Basics of scientific programming I 1.1 Introduction The aim of this course is use computing software platforms to solve scientific and

More information

Introduction to Python, Cplex and Gurobi

Introduction to Python, Cplex and Gurobi Introduction to Python, Cplex and Gurobi Introduction Python is a widely used, high level programming language designed by Guido van Rossum and released on 1991. Two stable releases: Python 2.7 Python

More information

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017

Numerical Modelling in Fortran: day 2. Paul Tackley, 2017 Numerical Modelling in Fortran: day 2 Paul Tackley, 2017 Goals for today Review main points in online materials you read for homework http://www.cs.mtu.edu/%7eshene/courses/cs201/notes/intro.html More

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Kristian Sandberg Department of Applied Mathematics University of Colorado Goal The goal with this worksheet is to give a brief introduction to the mathematical software Matlab.

More information

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT PROGRAMMING WITH MATLAB DR. AHMET AKBULUT OVERVIEW WEEK 1 What is MATLAB? A powerful software tool: Scientific and engineering computations Signal processing Data analysis and visualization Physical system

More information

Chapter 2: Basic Elements of Java

Chapter 2: Basic Elements of Java Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30

More information

USER-DEFINED ELEMENT IN ZMAN TM

USER-DEFINED ELEMENT IN ZMAN TM ZIVE Application Note6: User defined element in ZMAN USER-DEFINED ELEMENT IN ZMAN TM How to add a new user-defined element? Introduced by ZMAN 2.2, the SIMPLE category provides you with a functionality

More information

ME1107 Computing Y Yan.

ME1107 Computing Y Yan. ME1107 Computing 1 2008-2009 Y Yan http://www.staff.city.ac.uk/~ensyy About Fortran Fortran Formula Translation High level computer language Basic, Fortran, C, C++, Java, C#, (Matlab) What do we learn?

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Department of Computer Science and Information Systems Tingting Han (afternoon), Steve Maybank (evening) tingting@dcs.bbk.ac.uk sjmaybank@dcs.bbk.ac.uk Autumn 2017 Week 4: More

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

Structured Programming. Dr. Mohamed Khedr Lecture 4

Structured Programming. Dr. Mohamed Khedr Lecture 4 Structured Programming Dr. Mohamed Khedr http://webmail.aast.edu/~khedr 1 Scientific Notation for floats 2.7E4 means 2.7 x 10 4 = 2.7000 = 27000.0 2.7E-4 means 2.7 x 10-4 = 0002.7 = 0.00027 2 Output Formatting

More information

C++ Programming Lecture 11 Functions Part I

C++ Programming Lecture 11 Functions Part I C++ Programming Lecture 11 Functions Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Introduction Till now we have learned the basic concepts of C++. All the programs

More information

Fortran. (FORmula TRANslator) History

Fortran. (FORmula TRANslator) History Fortran (FORmula TRANslator) History FORTRAN vs. Fortran 1954 FORTRAN first successful high level language John Backus (IBM) 1958 FORTRAN II (Logical IF, subroutines, functions) 1961 FORTRAN IV 1966 FORTRAN

More information

9 Using Equation Networks

9 Using Equation Networks 9 Using Equation Networks In this chapter Introduction to Equation Networks 244 Equation format 247 Using register address lists 254 Setting up an enable contact 255 Equations displayed within the Network

More information

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

Introduction to Fortran

Introduction to Fortran Introduction to Fortran Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_us

More information

Intrinsic Functions Outline

Intrinsic Functions Outline Intrinsic Functions Outline 1. Intrinsic Functions Outline 2. Functions in Mathematics 3. Functions in Fortran 90 4. A Quick Look at ABS 5. Intrinsic Functions in Fortran 90 6. Math: Domain Range 7. Programming:

More information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

More information

Methods CSC 121 Fall 2016 Howard Rosenthal

Methods CSC 121 Fall 2016 Howard Rosenthal Methods CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

Programming in QBasic

Programming in QBasic Programming in QBasic Second lecture Constants In QBASIC: Constants In QBASIC division into three types: 1. Numeric Constants: there are two types of numeric constants: Real: the numbers used may be written

More information

Methods CSC 121 Spring 2017 Howard Rosenthal

Methods CSC 121 Spring 2017 Howard Rosenthal Methods CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

VARIABLES Storing numbers:

VARIABLES Storing numbers: VARIABLES Storing numbers: You may create and use variables in Matlab to store data. There are a few rules on naming variables though: (1) Variables must begin with a letter and can be followed with any

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions.

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions Grace Murray Hopper Expressions Eric Roberts CSCI 121 January 30, 2018 Grace Hopper was one of the pioneers of modern computing, working with

More information

Lecture 2 FORTRAN Basics. Lubna Ahmed

Lecture 2 FORTRAN Basics. Lubna Ahmed Lecture 2 FORTRAN Basics Lubna Ahmed 1 Fortran basics Data types Constants Variables Identifiers Arithmetic expression Intrinsic functions Input-output 2 Program layout PROGRAM program name IMPLICIT NONE

More information

Matlab as a calculator

Matlab as a calculator Why Matlab? Matlab is an interactive, high-level, user-friendly programming and visualization environment. It allows much faster programs development in comparison with the traditional low-level compiled

More information

Basic Types and Formatted I/O

Basic Types and Formatted I/O Basic Types and Formatted I/O C Variables Names (1) Variable Names Names may contain letters, digits and underscores The first character must be a letter or an underscore. the underscore can be used but

More information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

More information

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

Annotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments

Annotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments Variables, Data Types, and More Introduction In this lesson will introduce and study C annotation and comments C variables Identifiers C data types First thoughts on good coding style Declarations vs.

More information

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng. CS 265 Computer Architecture Wei Lu, Ph.D., P.Eng. 1 Part 1: Data Representation Our goal: revisit and re-establish fundamental of mathematics for the computer architecture course Overview: what are bits

More information

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill

Computational Methods of Scientific Programming. Lecturers Thomas A Herring Chris Hill 12.010 Computational Methods of Scientific Programming Lecturers Thomas A Herring Chris Hill Review of last lecture Start examining the FORTRAN language Development of the language Philosophy of language:

More information

ELEMENTARY MATLAB PROGRAMMING

ELEMENTARY MATLAB PROGRAMMING 1 ELEMENTARY MATLAB PROGRAMMING (Version R2013a used here so some differences may be encountered) COPYRIGHT Irving K. Robbins 1992, 1998, 2014, 2015 All rights reserved INTRODUCTION % It is assumed the

More information

Source: Fortran 90 3 Day Course (Univ. of Liverpool) URL: Ngo Van Thanh, NIMS Oct. 4, 2010

Source: Fortran 90 3 Day Course (Univ. of Liverpool) URL:   Ngo Van Thanh, NIMS Oct. 4, 2010 Source: Fortran 90 3 Day Course (Univ. of Liverpool) URL: http://www.liv.ac.uk/hpc/f90page.html Ngo Van Thanh, NIMS Oct. 4, 2010 II.1. Control Flow Overview: Fortran 90 supports the constructs: Conditional

More information

Allocating Storage for 1-Dimensional Arrays

Allocating Storage for 1-Dimensional Arrays Allocating Storage for 1-Dimensional Arrays Recall that if we know beforehand what size we want an array to be, then we allocate storage in the declaration statement, e.g., real, dimension (100 ) :: temperatures

More information

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Numerical Data. CS 180 Sunil Prabhakar Department of Computer Science Purdue University Numerical Data CS 180 Sunil Prabhakar Department of Computer Science Purdue University Problem Write a program to compute the area and perimeter of a circle given its radius. Requires that we perform operations

More information

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. I Internal Examination Sept. 2018 Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs. [I]Very short answer questions (Max 40 words). (5 * 2 = 10) 1. What is

More information

Homework #3 CS2255 Fall 2012

Homework #3 CS2255 Fall 2012 Homework #3 CS2255 Fall 2012 MULTIPLE CHOICE 1. The, also known as the address operator, returns the memory address of a variable. a. asterisk ( * ) b. ampersand ( & ) c. percent sign (%) d. exclamation

More information

Summary of basic C++-commands

Summary of basic C++-commands Summary of basic C++-commands K. Vollmayr-Lee, O. Ippisch April 13, 2010 1 Compiling To compile a C++-program, you can use either g++ or c++. g++ -o executable_filename.out sourcefilename.cc c++ -o executable_filename.out

More information

Special Section: Building Your Own Compiler

Special Section: Building Your Own Compiler cshtp6_19_datastructures_compiler.fm Page 1 Tuesday, February 14, 2017 10:31 AM 1 Chapter 19 Special Section: Building Your Own Compiler In Exercises8.31 8.33, we introduced Simpletron Machine Language

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

10. Additional Intrinsic Data Types

10. Additional Intrinsic Data Types 10. Additional Intrinsic Data Types Example: You have written a test driver for SGESV in LAPACK consists of the following steps: 1. Generate the elements of the matrix [A] and the vector {x_exact} using

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Names and Identifiers A program (that is, a class) needs a name public class SudokuSolver {... 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations,

More information

1 Characters & Strings in Fortran

1 Characters & Strings in Fortran Handout Four March 2, 2006 1 Characters & Strings in Fortran 1.1 Declaration In handout two of your notes (section 2.3) you were briefly shown how to declare various character types. A table similar to

More information

Tokens, Expressions and Control Structures

Tokens, Expressions and Control Structures 3 Tokens, Expressions and Control Structures Tokens Keywords Identifiers Data types User-defined types Derived types Symbolic constants Declaration of variables Initialization Reference variables Type

More information

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1 Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to

More information

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols. EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic

More information

Primitive Data Types: Intro

Primitive Data Types: Intro Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

More information

Operations. Making Things Happen

Operations. Making Things Happen Operations Making Things Happen Object Review and Continue Lecture 1 2 Object Categories There are three kinds of objects: Literals: unnamed objects having a value (0, -3, 2.5, 2.998e8, 'A', "Hello\n",...)

More information

Professor Peter Cheung EEE, Imperial College

Professor Peter Cheung EEE, Imperial College 1/1 1/2 Professor Peter Cheung EEE, Imperial College In this lecture, we take an overview of the course, and briefly review the programming language. The rough guide is not very complete. You should use

More information

Product Price Formula extension for Magento2. User Guide

Product Price Formula extension for Magento2. User Guide Product Price Formula extension for Magento2 User Guide version 1.0 Page 1 Contents 1. Introduction... 3 2. Installation... 3 2.1. System Requirements... 3 2.2. Installation...... 3 2.3. License... 3 3.

More information

Python Programming Exercises 1

Python Programming Exercises 1 Python Programming Exercises 1 Notes: throughout these exercises >>> preceeds code that should be typed directly into the Python interpreter. To get the most out of these exercises, don t just follow them

More information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

Python Programming: An Introduction to Computer Science

Python Programming: An Introduction to Computer Science Python Programming: An Introduction to Computer Science Chapter 3 Computing with Numbers Python Programming, 3/e 1 Objectives n To understand the concept of data types. n To be familiar with the basic

More information

Introduction to C++ Introduction and History. Characteristics of C++

Introduction to C++ Introduction and History. Characteristics of C++ Introduction and History Introduction to C++ Until 1980, C programming was widely popular, and slowly people started realizing the drawbacks of this language and at the same time, the engineers had come

More information

Process Optimization

Process Optimization Process Optimization Tier II: Case Studies Section 1: Lingo Optimization Software Optimization Software Many of the optimization methods previously outlined can be tedious and require a lot of work to

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers Chapter 03: Computer Arithmetic Lesson 09: Arithmetic using floating point numbers Objective To understand arithmetic operations in case of floating point numbers 2 Multiplication of Floating Point Numbers

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Unit 3. Constants and Expressions

Unit 3. Constants and Expressions 1 Unit 3 Constants and Expressions 2 Review C Integer Data Types Integer Types (signed by default unsigned with optional leading keyword) C Type Bytes Bits Signed Range Unsigned Range [unsigned] char 1

More information

ME 142 Engineering Computation I. Unit 1.2 Excel Functions

ME 142 Engineering Computation I. Unit 1.2 Excel Functions ME 142 Engineering Computation I Unit 1.2 Excel Functions TOA Make sure to submit TOA If not submitted, will receive score of 0 Common Questions from 1.1 & 1.2 Named Cell PP 1.1.2 Name cell B2 Payrate

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Variables and Constants

Variables and Constants 87 Chapter 5 Variables and Constants 5.1 Storing Information in the Computer 5.2 Declaring Variables 5.3 Inputting Character Strings 5.4 Mistakes in Programs 5.5 Inputting Numbers 5.6 Inputting Real Numbers

More information