Edit Descriptors. Decimal form. Fw.d Exponential form Ew.d Ew.dEe Scientific form ESw.d ESw.dEe Engineering form ENw.d ENw.dEe.

Size: px
Start display at page:

Download "Edit Descriptors. Decimal form. Fw.d Exponential form Ew.d Ew.dEe Scientific form ESw.d ESw.dEe Engineering form ENw.d ENw.dEe."

Transcription

1 Format Edit Descriptors The tedious part of using Fortran format is to master many format edit descriptors. Each edit descriptor tells the system how to handle certain type of values or activity. Each value requires some positions. For example, an integer of four digits requires at least four positions to print. Therefore, the number of positions to be used is the most important information in an edit descriptor. We shall use the following convention of symbols: w: the number of positions to be used m: the minimum number of positions to be used d: the number of digits to the right of the decimal point e: the number of digits in the exponent part Although we may print a number using as many positions as you want, this is only for input/output. This number of positions is not the precision (i.e., the number of significant digits) of that number. To be more precisely, computers normally can store real numbers up to seven significant digits. This is the precision of real numbers. However, we can print a real number using 50 positions in which 25 positions are for the fraction part. This is only a way of describing the appearance and does not change the precision of real numbers. The following are the editor descriptors to be discussed. Purpose Edit Descriptors Reading/writing INTEGERs Iw Iw.m Reading/writing REALs Reading/writing LOGICALs Decimal form Fw.d Exponential form Ew.d Ew.dEe Scientific form ESw.d ESw.dEe Engineering form ENw.d ENw.dEe Reading/writing CHARACTERs A Aw Positioning Others Horizontal Lw nx Tabbing Tc TLc and TRc Vertical / Grouping r(...) Format Scanning Control : Sign Control Blank Control S, SP and SS BN and BZ Most edit descriptors can be repeated and several edit descriptors can be grouped into a group. For most of the cases, edit descriptors are separated by commas. The following is an example: CHARACTER(LEN=30) :: Format Format = "(5X, I5.2, F10.3, A, ES14.7)" READ(*,Format)... variables...

2 WRITE(*,Format)... variables and expressions... In the above example, format Format has five edit descriptors 5X, I5.2, F10.3, A and ES14.7. Adjacent edit descriptors are separated by a comma. The I Descriptor The Iw and Iw.m descriptors are for INTEGER output. The general form of these descriptors are as follows: The meaning of r, w and m are: riw and riw.m I is for INTEGER w is the width of field, which indicates that an integer should be printed with w positions. m indicates that at least m positions (of the w positions) must contain digits. If the number to be printed has fewer than m digits, leading 0s are filled. If the number has more than m digits, m is ignored and in this case Iw.m is equivalent to Iw. Examples Note that w must be positive and larger than or equal to m. Let us look at the following example. There are three INTEGER variables a, b and c with values 123, -123 and , respectively. In the following table, the WRITE statements are shown in the left and their corresponding output, all using five positions, are shown in the right. The F Descriptor The Fw.d descriptor is for REAL output. The general form is: rfw.d The meaning of r, w and d are: F is for REAL

3 w is the width of field, which indicates that a real number should be printed with w positions. d indicates the number of digits after the decimal point. More precisely, of these w positions, the right-most d positions are for the fraction part of a real number, and the d+1 position from the right is a decimal point. The remaining w-(d+1) positions are for the integral part. This is shown in the figure below: Examples Let us look at the following example. There are two REAL variables a and b with values and , respectively. In the following table, the WRITE statements are shown in the left and their corresponding output, all using five positions, are shown in the right. The E Descriptor The Ew.d and Ew.dEe descriptors are for REAL output. The printed numbers will be in an exponential form. The general form of these descriptors are discussed below. There are two more forms, ESw.d and ENw.d, which will be discussed at the bottom of this page. The meaning of r, w, d and e are: rew.d and rew.dee E is for REAL numbers in exponential forms. w is the width of field, which indicates that a real number should be printed with w positions. To print a number in an exponential form, it is first converted to a normalized form s0.xxx...xxx 10 sxx, where s is the sign of the number and the exponent and x is a digit. For example, , , and are converted to , , and The Ew.d descriptor generates real numbers in the following form:

4 Examples In the following table, the WRITE statements use different E edit descriptors to print the value of The WRITE statements are shown in the left and their corresponding output, all using 12 positions, are shown in the right. Editor Descriptor ESw.d and ESw.dEe Scientists write the exponential form in a slightly different way. This ES edit descriptor is for printing a real number in scientific form, which has a non-zero digit as the integral part. If the number is a zero, then all digits printed will be zero. The following shows the printed form: The L Descriptor The Lw descriptor is for LOGICAL output. While Fortran uses.true. and.false. to indicate logical values true and false, respectively, the output only show T and F. The general form of this descriptor is as follows: The meaning of r and w are: rlw L is for LOGICAL w is the width of field, which indicates that a logical value should be printed with w positions. The output of a LOGICAL value is either T for.true. or F for.false. The single character value is shown in the right-most position and the remaining w-1 positions are filled with spaces. The is shown in the figure below.

5 Examples Let us look at the following example. There are two LOGICAL variables a and b with values.true. and.false., respectively. In the following table, the WRITE statements are shown in the left and their corresponding output are shown in the right. The A Descriptor The A and Aw descriptors are for CHARACTER output. The general form of these descriptors are as follows: The meaning of r and w are: ra and raw A is for CHARACTER w is the width of field, which indicates that a character string should be printed with w positions. The output of the character string depends on two factors, namely the length of the character string and the value of w. Here are the rules: o If w is larger than the length of the character string, all characters of the string can be printed and are right-justified. Also, leading spaces will be added. The following example prints the string "12345" of length 5 (i.e., five characters) using A6. o WRITE(*,'(A6)') "12345" Since w is larger than the length of the string, all five characters are printed and right-justified. The result is shown below: Examples Let us look at the following example. CHARACTER(LEN=5) :: a = "12345" CHARACTER :: b = "*" In the following table, the WRITE statements are shown at the left and their corresponding output are shown at the right.

6 Functions and Modules Syntax In addition to intrinsic functions, Fortran allows you to design your own functions. A Fortran function, or more precisely, a Fortran function subprogram, has the following syntax: type FUNCTION function-name (arg1, arg2,..., argn) [specification part] [execution part] [subprogram part] END FUNCTION function-name Example: Problem Statement Write a program to compute the cubes of 1, 2, 3,..., 10 in both INTEGER and REAL types. It is realcube() for computing the cube of a required to write a function intcube() for computing the cube of an integer and a function real. Solution! ! This program display the cubes of INTEGERs and! REALs. The cubes are computed with two functions:! PROGRAM Cubes INTEGER, PARAMETER :: Iterations = 10 INTEGER :: i REAL :: x DO i = 1, Iterations x = i WRITE(*,*) i, x, intcube(i), realcube(x) END DO CONTAINS

7 ! ! INTEGER FUNCTION intcube() :! This function returns the cube of the argument.! INTEGER FUNCTION intcube(number) INTEGER, INTENT(IN) :: Number intcube = Number*Number*Number END FUNCTION intcube! ! REAL FUNCTION realcube() :! This function returns the cube of the argument.! REAL FUNCTION realcube(number) REAL, INTENT(IN) :: Number realcube = Number*Number*Number END FUNCTION realcube END PROGRAM Cubes. Program Input and Output The following is the output from the above program. 1, 1., 1, 1. 2, 2., 8, 8. 3, 3., 27, 27. 4, 4., 64, 64. 5, 5., 125, , 6., 216, , 7., 343, , 8., 512, , 9., 729, , 10., 1000, What is a Module? In many previous example, there are several internal functions packed at the end of the main program. In fact, many of them such as Factorial(), Combinatorial(), GCD(), and Prime() are general functions that can also be used in other programs. To provide the programmers with a way of packing commonly used functions into a few tool-boxes, Fortran 90 has a new capability called modules. It has a syntactic form very similar to a main program, except for something that are specific to modules. Syntax The following is the syntax of a module: MODULE module-name

8 [specification part] CONTAINS [internal-functions] END MODULE module-name The differences between a program and a module are the following: The structure of a module is almost identical to the structure of a program. However, a module starts with the keyword MODULE and ends with END MODULE rather than PROGRAM and END PROGRAM. A module has specification part and could contain internal function; but, it does not have any statements between the specification part and the keyword CONTAINS. Consequently, a module does not contains statements to be executed as in a program. A module can only contain declarations and functions to be used by other modules and programs. This is perhaps one of the most important difference. As a result, a module cannot exist alone; it must be used with other modules and a main program Short Examples Here are some short examples of modules: The following is a very simple module. It has the specification part and does not have any internal function. The specification part has two REAL PARAMETERs, namely PI and g and one INTEGER variable Counter. MODULE SomeConstants REAL, PARAMETER :: PI = REAL, PARAMETER :: g = 980 INTEGER :: Counter END MODULE SomeConstants The following module SumAverage does not have any specification part (hence no ); but it does contain two functions, Sum() and Average(). Please note that function Average() uses Sum() to compute the sum of three REAL numbers. MODULE SumAverage CONTAINS REAL FUNCTION Sum(a, b, c) REAL, INTENT(IN) :: a, b, c Sum = a + b + c END FUNCTION Sum REAL FUNCTION Average(a, b, c) REAL, INTENT(IN) :: a, b, c Average = Sum(a,b,c)/2.0 END FUNCTION Average END MODULE SumAverage The following module DegreeRadianConversion contains two PARAMETERs, PI and Degree180, and two functions DegreeToRadian() and RadianToDegree(). The two PARAMETERs are used in the conversion functions. Note that these parameters are global to the two functions. See scope rules for the details. MODULE DegreeRadianConversion

9 REAL, PARAMETER :: PI = REAL, PARAMETER :: Degree180 = REAL FUNCTION DegreeToRadian(Degree) REAL, INTENT(IN) :: Degree DegreeToRadian = Degree*PI/Degree180 END FUNCTION DegreeToRadian REAL FUNCTION RadianToDegree(radian) REAL, INTENT(IN) :: Radian RadianToDegree = Radian*Degree180/PI END FUNCTION RadianToDegree END MODULE DegreeRadianConversion Problem Statement The combinatorial coefficient C(n,r) is defined as follows: where 0 <= r <= n must hold. Write a module that contains two functions: (1) Factorial() and (2) Combinatorial(). The former computes the factorial of its argument, while the latter uses the former to compute the combinatorial coefficient. Then, write a main program that uses this module. Solution The following is the desired module:! MODULE FactorialModule! This module contains two procedures: Factorial(n) and! Combinatorial(n,r). The first computes the factorial of an integer! n and the second computes the combinatorial coefficient of two! integers n and r. MODULE FactorialModule CONTAINS! FUNCTION Factorial() :! This function accepts a non-negative integers and returns its! Factorial. INTEGER FUNCTION Factorial(n) INTEGER, INTENT(IN) :: n! the argument INTEGER :: Fact, i! result

10 Fact = 1! initially, n!=1 DO i = 1, n! this loop multiplies Fact = Fact * i! i to n! END DO Factorial = Fact END FUNCTION Factorial! FUNCTION Combinarotial():! This function computes the combinatorial coefficient C(n,r).! If 0 <= r <= n, this function returns C(n,r), which is computed as! C(n,r) = n!/(r!*(n-r)!). Otherwise, it returns 0, indicating an! error has occurred. INTEGER FUNCTION Combinatorial(n, r) INTEGER, INTENT(IN) :: n, r INTEGER :: Cnr IF (0 <= r.and. r <= n) THEN! valid arguments? Cnr = Factorial(n) / (Factorial(r)*Factorial(n-r)) ELSE! no, Cnr = 0! zero is returned END IF Combinatorial = Cnr END FUNCTION Combinatorial END MODULE FactorialModule Here is the main program:! PROGRAM ComputeFactorial:! This program uses MODULE FactorialModule for computing factorial! and combinatorial coefficients. PROGRAM ComputeFactorial USE FactorialModule! use a module INTEGER :: N, R WRITE(*,*) 'Two non-negative integers --> ' READ(*,*) N, R WRITE(*,*) N, WRITE(*,*) R, '! = ', Factorial(N) '! = ', Factorial(R) IF (R <= N) THEN! if r <= n, do C(n,r) WRITE(*,*) 'C(', N, ',', R, ') = ', Combinatorial(N, R) ELSE! otherwise, do C(r,n) WRITE(*,*) 'C(', R, ',', N, ') = ', Combinatorial(R, N) END IF END PROGRAM ComputeFactorial. Program Input and Output

11 The following is the output from the above program. Two non-negative integers --> ! = ! = 24 C(13,4) = 221 Subroutines YYYYMMDD to Year, Month, Day Conversion Problem Statement In data processing, the year, month and day information are usually written as yyyymmdd, where the first four digits are Year, the fifth and sixth digits are Month, and the last two digits are Day. For example, means April 8, 1971, and means January 1, Write a program to read an integer in the form of yyyymmdd and extract the values of Year, Month and Day. Do it with an external subroutine. Solution! PROGRAM YYYYMMDDConversion:! This program uses an external subroutine Conversion() to convert! an integer value in the form of YYYYMMDD to Year, Month and Day. PROGRAM YYYYMMDDConversion INTERFACE! interface block SUBROUTINE Conversion(Number, Year, Month, Day) INTEGER, INTENT(IN) :: Number INTEGER, INTENT(OUT) :: Year, Month, Day END SUBROUTINE Conversion END INTERFACE INTEGER :: YYYYMMDD, Y, M, D DO! loop until a zero is seen WRITE(*,*) "A YYYYMMDD (e.g., ) please (0 to stop) -> " READ(*,*) YYYYMMDD! read in the value IF (YYYYMMDD == 0) EXIT! if 0, then bail out CALL Conversion(YYYYMMDD, Y, M, D)! do conversation WRITE(*,*) "Year = ", Y WRITE(*,*) "Month = ", M WRITE(*,*) "Day = ", D WRITE(*,*) END DO END PROGRAM YYYYMMDDConversion! display results

12 ! SUBROUTINE Conversion():! This external subroutine takes an integer input Number in the! form of YYYYMMDD and convert it to Year, Month and Day. SUBROUTINE Conversion(Number, Year, Month, Day) INTEGER, INTENT(IN) :: Number INTEGER, INTENT(OUT) :: Year, Month, Day Year = Number / Month = MOD(Number, 10000) / 100 Day = MOD(Number, 100) END SUBROUTINE Conversion. Program Input and Output The following is the output from the above program for the input 3.0, 6.0 and 8.0: A YYYYMMDD (e.g., ) please (0 to stop) -> Year = 1997 Month = 10 Day = 26 A YYYYMMDD (e.g., ) please (0 to stop) -> Year = 2016 Month = 1 Day = 31 A YYYYMMDD (e.g., ) please (0 to stop) -> Year = 1901 Month = 1 Day = 3 A YYYYMMDD (e.g., ) please (0 to stop) -> 0 Use of arrays and array sections The English word "array" is translated into Swedish as "fält", which, retranslated into English, is "field". It is possible therefore, that we may use the word field either by mistake, or as a suitable name of a specific array. A new feature of Fortran 90 is that you can work directly with a whole array or an array section without explicit (or implicit) DO-loops. In the old Fortran you could in some circumstances work directly with a whole array, but then only during I/O processing. An array is defined to have a shape, given by its number of dimensions, called "rank", and the extent of each dimension. Two arrays agree if they have the same shape. Operations are normally done element by element. Please note that the rank of an array is the number of dimensions and has nothing to do with the mathematical rank of a matrix!

13 In the following simple example I show how you can assign matrices with simple statements like B = A, how you can use the intrinsic matrix multiplication MATMUL and the addition SUM, and how you can use the array sections (in the example below I use array sections which are vectors). PROGRAM ARRAY_EXAMPLE INTEGER REAL, DIMENSION (4,4) DO I = 1, 4 END DO DO J = 1, 4 A(I, J) = (I-1.2)**J END DO :: I, J :: A, B, C, D, E! calculate a test matrix B = A*A! element for element multiplication CALL PRINTF(A,4) ; CALL PRINTF(B,4) C = MATMUL(A, B)! internal matrix multiplication DO I = 1, 4! explicit matrix multiplication DO J = 1, 4 D(I, J) = SUM( A(I,:)*B(:,J) ) END DO END DO CALL PRINTF(C,4) ; CALL PRINTF(D,4) E = C - D! comparison of the two methods CALL PRINTF(E,4) CONTAINS SUBROUTINE PRINTF(A, N)! print an array INTEGER :: N, I REAL, DIMENSION (N, N) :: A DO I = 1, N WRITE(*,' (4E15.6)') A(I,:) END DO WRITE(*,*)! write the blank line END SUBROUTINE PRINTF END PROGRAM ARRAY_EXAMPLE Read and Write (internal file) Sometimes it is convenient in a Fortran program to use files for accessing or storing data - especially when large amounts of data are involved. Too much keyboard input during the run of a program leads to mistakes and tedium, while too much screen output has similar consequences. Putting data into files - both for input and output - is a more leisurely and less error-prone approach. Open The open command is used to open files - that is, it makes files available so that Fortran can read or write to them. The simplest form of the command is open (unit = number, file = "name"). In place of number you insert a positive integer (but not 6) to be used to refer to the file, and instead of name you insert the name of the file. Here are examples of open commands: open (unit = 2, file = "scores") open (unit = 7, file = "a:scores.txt")

14 open (unit = 5, file = "h:primes") open (unit = 24, file = "c:divisors.dat"). Fortran uses the unit number to access the file with later read and write statements. Several files can be open at once, but each must have a different number. There is one thing to remember about numbering a file - you cannot use the number 6, as GNU Fortran reserves that number to refer to the screen. Note that quotes enclose the filename. If you do not specify the drive of the file, or if you specify the same drive upon which GNU Fortran is installed, GNU Fortran will by default assume the file is located on the same drive and in the same directory from where Fortran is running. If you specify a drive letter different from where GNU Fortran is installed, it will look for or place the file in the main root directory of the specified drive. Unfortunately you cannot specify a directory address - the compiler will produce an error message if you do. Observe that you do not include a backslash before the file name - nor do you put a space on either side of the colon after the drive letter. If the named file does not already exist, Fortran will create it; if it does exist, Fortran will replace it. (So don't mistakenly give the file the same name as another important file!) Close The close command is used to close one or more files - examples are close (5), close (1, 3, 8). The first of these commands closes the file numbered 5, while the second closes the three files numbered 1, 3, and 8. It is not necessary to close files; all files will automatically be closed when an end or stop statement is executed. However, in programs handling large amounts of data it can be prudent to close files before the end of the program in order to avoid possible memory problems and to increase efficiency. Write (to Files) The write command is used to write data to a file. For example, the command write (7,*) works like a print * command, except that data is written to the file numbered 7 instead of to the screen. The two statements print *, "The solutions to the equation are : ", x1, x2 write (7,*) "The solutions to the equation are : ", x1, x2 produce exactly the same output, except that the first writes to the screen and the second to file number 7. The command "write (7,*)" on a line by itself serves as a line feed, skipping a line in the file numbered 7 before the next writing to that file. You can also use write statements in conjunction with format statements to write to a file; this gives you better control of formatting. In the following, the first number in "write (7,5)" refers to the file number and the second to the label of the format statement: write (7,5) "The solutions are ", x1, " and ", x2 5 format (a,f16.10,a,f16.10) The "write (7,5)" command works exactly like the similar command "write (*,5)", except that in the former output is directed to file number 7, and in the latter to the screen.

15 Each execution of a write command writes to a single line in a file. The next write command will write to a new line. Here is a program that finds and prints to a file the divisors of an integer n : program divisors c This program finds the divisors of an integer input by the user. c The divisors are printed to a file. integer n, k, d(10) open (unit = 1, file = "divisors") print *, "Enter a positive integer :" read *, n write (1,*) "Here are the divisors of ", n, " :" k = 0 do i = 1, n if (mod(n,i).eq. 0) then k = k + 1 d(k) = i end if if (k.eq. 10) then write (1,5) (d(j), j = 1, 10) k = 0 end if end do write (1,5) (d(j), j = 1, k) 5 format (10i7) close (1) print *, "The divisors are listed in the file 'divisors'. Bye." end Note that the program counts the divisors, storing them in an array d, until 10 are accumulated; then it prints these 10 on a single line, reserving 7 places for each divisor. It then begins a new count and repeats the procedure until all divisors are found. The last write statement prints whatever divisors are left over after the last full line of 10. The close statement, included here for demonstration only, is unnecessary, as the program is all but finished at that point and the end statement will automatically close the file anyway. Read (from Files) The read statement is used to read data from a file. Generally data is read from a file in the standard way, line-by-line and from left to right. But you must remember that each read statement begins reading a new line, whether or not the preceding read statement used all the data in the preceding line. Suppose for example that a file is numbered 7, and that the first two lines of the file contain the data (separated by commas) 1.23, 4.56, 7.89

16 11, 13, "Sally" If the first two read statements in the program are read (7,*) x, y, z read (7,*) m, n, first, then the program assigns x = 1.23, y = 4.56, z = 7.89, m = 11, n = 13, first = "Sally". The variables will have to be declared in the program to correspond with the data assigned them by the read statements. For instance, in the above situation x, y, and z will have been declared real variables, m and n integers, and "first" a character variable. Failure to match variable types with data types will most likely lead to error messages. It is possible that a program does not know beforehand the length of a file. If data is being read from a loop, there is a way to exit the loop when all data in the file has been read, thereby avoiding a program hang-up. One simply modifies the read statement to something like read (7,*,end=10). This command instructs Fortran to read the next line in the file numbered 7, but to jump to the statement labelled 10 in the program in the event that the last line in that file has already been read. You can also use format specifiers in read statements, but this can be somewhat tedious and we will not go into the details. As but one example, suppose you want to make the assignments n = 77, x = , y = 67.8, where n is an integer and x and y are real variables. Then you may use the read and format statements read (7,5) n, x, y 5 format (i2,f5.2,f3.1), and in file number 7 place the corresponding line of data Fortran will read and separate the data, insert appropriate decimal points, and assign it to the variables. But as you can see the method is confusing and perhaps not worth the effort. Home Work: Problem Statement 1 Write a program that for x = 2.0, 1.8, 1.6, 1.4,..., 0.8, 0.6, 0.4 and 0.2, prints the sequence number of the value (i.e., 1, 2, 3 and so on), the value itself, and its LOG(x) four times using E, E with three digits for the exponent, ES and EN descriptors. You should generate the output as shown below E E E E-03

17 E E E E E E E E-03 : : : E E E E+00 Problem Statement 2. We have discussed Newton's Method for computing the square root of a positive number. Let the given number be b and let x be a rough guess of the square root of b. Newton's method suggests that a better guess, New x can be computed as follows: One can start with b as a rough guess and compute New x; from New x, one can generate a even better guess, until two successive guesses are very close. Either one could be considered as the square root of b. Write a function MySqrt() that accepts a formal argument and uses Newton's method to computes its square root. Then, write a main program that reads in an initial value, a final value, and a step size, and computes the square roots of these successive values with Newton'e method and Fortran's SQRT() function, and determines the absolute error. Problem Statement 3. A file is to contain a list of names and nick names, to each of which there corresponds a telephone number (students in our class). Write a program which opens this file and new file and copies the list from old file to new file, closing it for use in a new program. Problem Statement 4 Given the array declaration. REAL, Dimension (50,20) :: A a) Write array sections representing i) the first roe of A; ii) the last column of A; iii) every second element in each row and column; Problem Statement 5.

18 Using only array syntax (not DO statement) write a program which a) define an array to have 100 elements; b) assigns to the elements the values 1,2,3, 100 c) reads two integer values in the range 1 to 100; d) reverses the order of the elements of array in the range specified by the two values. Problem Statement 6 It is known that 1 cm is equal to inch and 1 inch is equal to 2.54 cm. Write a program to convert 0, 0.5, 1, 1.5,..., 8, 8.5, 9, 9.5, and 10 from cm to inch and from inch to cm.

Lecture-6 Lubna Ahmed

Lecture-6 Lubna Ahmed Lecture-6 Lubna Ahmed 1 Input/output Input/output List directed input/output Formatted (or user formatted) input/output 2 List directed Input/output Statements List directed I/O are said to be in free

More information

type FUNCTION function-name (arg1, arg2,..., argn)

type FUNCTION function-name (arg1, arg2,..., argn) FORTRAN Functions Syntax Form 1 type FUNCTION function-name (arg1, arg2,..., argn) [specification part] [execution part] [subprogram part] function-name Form 2 type FUNCTION function-name () [specification

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

write (unit=*,fmt=*) i =, i! will print: i = 3

write (unit=*,fmt=*) i =, i! will print: i = 3 I/O (F book, chapters 9, 10 and 15) All I/O in Fortran90 is record-based, typically with record delimiters of some kind. This is in contrast to C, which has stream I/O, with no record delimiters required.

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

Review Arrays Advanced Input/Output New Data Types Debugging Your Programs

Review Arrays Advanced Input/Output New Data Types Debugging Your Programs OUTLINE 1 REVIEW 2 ARRAYS The Concept Using Arrays 3 ADVANCED INPUT/OUTPUT Format Using Files 4 NEW DATA TYPES Creating Your Own Data Type 5 DEBUGGING YOUR PROGRAMS THE STORY SO FAR... Understand about

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

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

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

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

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

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011 Autumn 2015 Lecture 3, Simple C programming M. Eriksson (with contributions from A. Maki and

More information

Fortran 90 Two Commonly Used Statements

Fortran 90 Two Commonly Used Statements Fortran 90 Two Commonly Used Statements 1. DO Loops (Compiled primarily from Hahn [1994]) Lab 6B BSYSE 512 Research and Teaching Methods The DO loop (or its equivalent) is one of the most powerful statements

More information

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104)

Learning Language. Reference Manual. George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104) Learning Language Reference Manual 1 George Liao (gkl2104) Joseanibal Colon Ramos (jc2373) Stephen Robinson (sar2120) Huabiao Xu(hx2104) A. Introduction Learning Language is a programming language designed

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

AN INTRODUCTION TO FORTRAN 90 LECTURE 2. Consider the following system of linear equations: a x + a x + a x = b

AN INTRODUCTION TO FORTRAN 90 LECTURE 2. Consider the following system of linear equations: a x + a x + a x = b AN INTRODUCTION TO FORTRAN 90 LECTURE 2 1. Fortran 90. Arrays, functions and subroutines. 2. Scientific plotting. Gnuplot 1 Each coefficient and variable is a scalar. Lengthy and cumbersome! Program Scalar

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Basic Fortran I/O Concepts

Basic Fortran I/O Concepts Basic Fortran I/O Concepts LECTURE OUTLINE Free versus Directed I/O Edit Descriptors Carriage Control Numeric Control Character Control Spacing Control Repeat Specifier Read and Write to Files Examples!!

More information

9. Elementary Algebraic and Transcendental Scalar Functions

9. Elementary Algebraic and Transcendental Scalar Functions Scalar Functions Summary. Introduction 2. Constants 2a. Numeric Constants 2b. Character Constants 2c. Symbol Constants 2d. Nested Constants 3. Scalar Functions 4. Arithmetic Scalar Functions 5. Operators

More information

FORTRAN 90: Formatted Input/Output. Meteorology 227 Fall 2018

FORTRAN 90: Formatted Input/Output. Meteorology 227 Fall 2018 FORTRAN 90: Formatted Input/Output Meteorology 227 Fall 2018 Formatted Output Two output statements in FORTRAN PRINT and WRITE PRINT format-descriptor, output-list What is a format descriptor? * A character

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

8. Control statements

8. Control statements 8. Control statements A simple C++ statement is each of the individual instructions of a program, like the variable declarations and expressions seen in previous sections. They always end with a semicolon

More information

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++

Chapter 5. Repetition. Contents. Introduction. Three Types of Program Control. Two Types of Repetition. Three Syntax Structures for Looping in C++ Repetition Contents 1 Repetition 1.1 Introduction 1.2 Three Types of Program Control Chapter 5 Introduction 1.3 Two Types of Repetition 1.4 Three Structures for Looping in C++ 1.5 The while Control Structure

More information

Review More Arrays Modules Final Review

Review More Arrays Modules Final Review OUTLINE 1 REVIEW 2 MORE ARRAYS Using Arrays Why do we need dynamic arrays? Using Dynamic Arrays 3 MODULES Global Variables Interface Blocks Modular Programming 4 FINAL REVIEW THE STORY SO FAR... Create

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

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

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

C for Engineers and Scientists

C for Engineers and Scientists C for Engineers and Scientists An Interpretive Approach Harry H. Cheng University of California, Davis 0.8 0.6 j0(t) j1(t) j2(t) j3(t) 0.4 Bessel functions 0.2 0-0.2-0.4-0.6 1 2 3 4 5 6 7 8 9 10 t Copyright

More information

Computers in Engineering. Subroutines Michael A. Hawker

Computers in Engineering. Subroutines Michael A. Hawker Computers in Engineering COMP 208 Subroutines Michael A. Hawker Subprograms Functions are one type of subprogram in FORTRAN Another type of subprogram FORTRAN allows is called a subroutine There are many

More information

Activity Overview A basic introduction to the many features of the calculator function of the TI-Nspire

Activity Overview A basic introduction to the many features of the calculator function of the TI-Nspire TI-Nspire Activity: An Introduction to the TI-Nspire Calculator Function By: Leigh T Baker Activity Overview A basic introduction to the many features of the calculator function of the TI-Nspire Concepts

More information

ADVANCED INPUT AND OUTPUT FORTRAN PROGRAMMING. Zerihun Alemayehu AAiT.CED Rm E119B

ADVANCED INPUT AND OUTPUT FORTRAN PROGRAMMING. Zerihun Alemayehu AAiT.CED Rm E119B ADVANCED INPUT AND OUTPUT FORTRAN PROGRAMMING Zerihun Alemayehu AAiT.CED Rm E119B SIMPLE INPUT AND OUTPUT READ, WRITE and PRINT statements are called list-directed READ*, a, b, c READ(*,*) a, b, c PRINT*,

More information

Should you know scanf and printf?

Should you know scanf and printf? C-LANGUAGE INPUT & OUTPUT C-Language Output with printf Input with scanf and gets_s and Defensive Programming Copyright 2016 Dan McElroy Should you know scanf and printf? scanf is only useful in the C-language,

More information

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute

Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Functional Programming in Haskell Prof. Madhavan Mukund and S. P. Suresh Chennai Mathematical Institute Module # 02 Lecture - 03 Characters and Strings So, let us turn our attention to a data type we have

More information

Subroutines, Functions and Modules

Subroutines, Functions and Modules Subroutines, Functions and Modules Subdividing the Problem Most problems are thousands of lines of code. Few people can grasp all of the details. Good design principle: Exhibit the overall structure in

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

APPENDIX B. Fortran Hints

APPENDIX B. Fortran Hints APPENDIX B Fortran Hints This appix contains hints on how to find errors in your programs, and how to avoid some common Fortran errors in the first place. The basics on how to invoke the Fortran compiler

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

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

Computers in Engineering COMP 208. Subprograms. Subroutines. Subroutines Michael A. Hawker

Computers in Engineering COMP 208. Subprograms. Subroutines. Subroutines Michael A. Hawker Computers in Engineering COMP 208 Subroutines Michael A. Hawker Subprograms Functions are one type of subprogram in FORTRAN Another type of subprogram FORTRAN allows is called a subroutine There are many

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n) Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Module 10A Lecture - 20 What is a function?

More information

SUBROUTINE subroutine-name (arg1, arg2,..., argn)

SUBROUTINE subroutine-name (arg1, arg2,..., argn) FORTRAN Subroutines Syntax Form 1 SUBROUTINE subroutine-name (arg1, arg2,..., argn) [specification part] [execution part] [subprogram part] subroutine-name Form 2 SUBROUTINE subroutine-name () [specification

More information

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #43. Multidimensional Arrays Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #43 Multidimensional Arrays In this video will look at multi-dimensional arrays. (Refer Slide Time: 00:03) In

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Fifth week Control Structures A program is usually not limited to a linear sequence of instructions. During its process

More information

Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

More information

3. Repetitive Structures (Loops)

3. Repetitive Structures (Loops) 3. Repetitive Structures (Loops) We can make a program to repeat sections of statements (iterate) by using the DO loop construct. There are three forms: The DO loop with a counter, The DO-EXIT Construct

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

LOOPS. Repetition using the while statement

LOOPS. Repetition using the while statement 1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while

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

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O

Overview of C. Basic Data Types Constants Variables Identifiers Keywords Basic I/O Overview of C Basic Data Types Constants Variables Identifiers Keywords Basic I/O NOTE: There are six classes of tokens: identifiers, keywords, constants, string literals, operators, and other separators.

More information

Chapter 2 THE STRUCTURE OF C LANGUAGE

Chapter 2 THE STRUCTURE OF C LANGUAGE Lecture # 5 Chapter 2 THE STRUCTURE OF C LANGUAGE 1 Compiled by SIA CHEE KIONG DEPARTMENT OF MATERIAL AND DESIGN ENGINEERING FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING Contents Introduction to

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 General Information Quick Overview This chapter is not intended to be a comprehensive manual of MATLAB R. Our sole aim is to provide sufficient information to give you a good

More information

Language Fundamentals

Language Fundamentals Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long

More information

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code CS102: Standard I/O Our next topic is standard input and standard output in C. The adjective "standard" when applied to "input" or "output" could be interpreted to mean "default". Typically, standard output

More information

Counting Loop: DO-END DO. DO var = initial-value, final-value, step-size

Counting Loop: DO-END DO. DO var = initial-value, final-value, step-size Counting Loop: - Syntax Form 1 var = initial-value, final-value, step-size statements Form 2 If step-size is 1, use var = initial-value, final-value statements var is a variable of type INTEGER. initial-value,

More information

Chapter 1 Operations With Numbers

Chapter 1 Operations With Numbers Chapter 1 Operations With Numbers Part I Negative Numbers You may already know what negative numbers are, but even if you don t, then you have probably seen them several times over the past few days. If

More information

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017

FORTRAN 90: Functions, Modules, and Subroutines. Meteorology 227 Fall 2017 FORTRAN 90: Functions, Modules, and Subroutines Meteorology 227 Fall 2017 Purpose First step in modular program design Cannot always anticipate all of the steps that will be needed to solve a problem Easier

More information

Programming for Engineers Introduction to C

Programming for Engineers Introduction to C Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

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

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual Contents 1 Introduction...2 2 Lexical Conventions...2 3 Types...3 4 Syntax...3 5 Expressions...4 6 Declarations...8 7 Statements...9

More information

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 7 Input/Output

ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 7 Input/Output ESCI 386 IDL Programming for Advanced Earth Science Applications Lesson 7 Input/Output Reading: Bowman, Chapters 10-12 READING FROM THE TERMINAL The READ procedure is used to read from the terminal. IDL

More information

Output: For each size provided as input, a figure of that size is to appear, followed by a blank line.

Output: For each size provided as input, a figure of that size is to appear, followed by a blank line. Problem 1: Divisor Differences Develop a program that, given integers m and k satisfying m > k > 0, lists every pair of positive integers (i,j) such that j i = k and both i and j are divisors of m. Input:

More information

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators Formatted Input and Output The printf function The scanf function Arithmetic and Assignment Operators Simple Assignment Side Effect

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 Quick Overview This chapter is not intended to be a comprehensive manual of MATLAB R. Our sole aim is to provide sufficient information to give you a good start. If you are

More information

do fifty two: Language Reference Manual

do fifty two: Language Reference Manual do fifty two: Language Reference Manual Sinclair Target Jayson Ng Josephine Tirtanata Yichi Liu Yunfei Wang 1. Introduction We propose a card game language targeted not at proficient programmers but at

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa

Functions. Autumn Semester 2009 Programming and Data Structure 1. Courtsey: University of Pittsburgh-CSD-Khalifa Functions Autumn Semester 2009 Programming and Data Structure 1 Courtsey: University of Pittsburgh-CSD-Khalifa Introduction Function A self-contained program segment that carries out some specific, well-defined

More information

Outline. Data and Operations. Data Types. Integral Types

Outline. Data and Operations. Data Types. Integral Types Outline Data and Operations Data Types Arithmetic Operations Strings Variables Declaration Statements Named Constant Assignment Statements Intrinsic (Built-in) Functions Data and Operations Data and Operations

More information

International Olympiad in Informatics 2012

International Olympiad in Informatics 2012 International Olympiad in Informatics 2012 23-30 September 2012 Sirmione - Montichiari, Italy Competition tasks, day 1: Leonardo's inventions and projects odometer English 1.2 Pebbling odometer Leonardo

More information

C Functions. 5.2 Program Modules in C

C Functions. 5.2 Program Modules in C 1 5 C Functions 5.2 Program Modules in C 2 Functions Modules in C Programs combine user-defined functions with library functions - C standard library has a wide variety of functions Function calls Invoking

More information

Formatted Input/Output

Formatted Input/Output Chapter 3 Formatted Input/Output 1 The printf Function The printf function must be supplied with a format string ( 格式化字串 ), followed by any values that are to be inserted into the string during printing:

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

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long

LESSON 5 FUNDAMENTAL DATA TYPES. char short int long unsigned char unsigned short unsigned unsigned long LESSON 5 ARITHMETIC DATA PROCESSING The arithmetic data types are the fundamental data types of the C language. They are called "arithmetic" because operations such as addition and multiplication can be

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

Computers in Engineering COMP 208 Repetition and Storage Michael A. Hawker. Repetition. A Table of Values 9/20/2007

Computers in Engineering COMP 208 Repetition and Storage Michael A. Hawker. Repetition. A Table of Values 9/20/2007 Computers in Engineering COMP 208 Repetition and Storage Michael A. Hawker Repetition To fully take advantage of the speed of a computer, we must be able to instruct it to do a lot of work The program

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Control Flow: Looping CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of Repeated Execution Loop: Group of

More information

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as:

11. Arrays. For example, an array containing 5 integer values of type int called foo could be represented as: 11. Arrays An array is a series of elements of the same type placed in contiguous memory locations that can be individually referenced by adding an index to a unique identifier. That means that, for example,

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

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

CSI33 Data Structures

CSI33 Data Structures Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

More information

C Programming

C Programming 204216 -- C Programming Chapter 3 Processing and Interactive Input Adapted/Assembled for 204216 by Areerat Trongratsameethong A First Book of ANSI C, Fourth Edition Objectives Assignment Mathematical Library

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

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

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

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng

Slide Set 2. for ENCM 335 in Fall Steve Norman, PhD, PEng Slide Set 2 for ENCM 335 in Fall 2018 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary September 2018 ENCM 335 Fall 2018 Slide Set 2 slide

More information

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed. Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

The Fortran Basics. Handout Two February 10, 2006

The Fortran Basics. Handout Two February 10, 2006 The Fortran Basics Handout Two February 10, 2006 A Fortran program consists of a sequential list of Fortran statements and constructs. A statement can be seen a continuous line of code, like b=a*a*a or

More information

Lesson 10. Student Outcomes. Lesson Notes

Lesson 10. Student Outcomes. Lesson Notes Student Outcomes Students understand that a function from one set (called the domain) to another set (called the range) assigns each element of the domain to exactly one element of the range and understand

More information

File Input and Output

File Input and Output 5. Input and Output File Input and Output read(i,j) write(i,j) j is the statement number of format statement. i is the I/O unit or logical unit associated with device or file. non-negative integer from

More information

Visual basic tutorial problems, developed by Dr. Clement,

Visual basic tutorial problems, developed by Dr. Clement, EXCEL Visual Basic Tutorial Problems (Version January 20, 2009) Dr. Prabhakar Clement Arthur H. Feagin Distinguished Chair Professor Department of Civil Engineering, Auburn University Home page: http://www.eng.auburn.edu/users/clemept/

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

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program

CMPT 102 Introduction to Scientific Computer Programming. Input and Output. Your first program CMPT 102 Introduction to Scientific Computer Programming Input and Output Janice Regan, CMPT 102, Sept. 2006 0 Your first program /* My first C program */ /* make the computer print the string Hello world

More information

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University AN OVERVIEW OF C, PART 3 CSE 130: Introduction to Programming in C Stony Brook University FANCIER OUTPUT FORMATTING Recall that you can insert a text field width value into a printf() format specifier:

More information

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points) Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

More information

C Language, Token, Keywords, Constant, variable

C Language, Token, Keywords, Constant, variable C Language, Token, Keywords, Constant, variable A language written by Brian Kernighan and Dennis Ritchie. This was to be the language that UNIX was written in to become the first "portable" language. C

More information