Fortran 95/2003 Course Exercises by Robert Barthel March 24, 2015 - - PowerPoint PPT Presentation

fortran 95 2003 course
SMART_READER_LITE
LIVE PREVIEW

Fortran 95/2003 Course Exercises by Robert Barthel March 24, 2015 - - PowerPoint PPT Presentation

Fortran 95/2003 Course Exercises by Robert Barthel March 24, 2015 STEINBUCH CENTRE FOR COMPUTING - SCC KIT University of the State of Baden-Wrttemberg and www.kit.edu National Laboratory of the Helmholtz Association Exercise 1.1


slide-1
SLIDE 1

KIT – University of the State of Baden-Württemberg and National Laboratory of the Helmholtz Association

STEINBUCH CENTRE FOR COMPUTING - SCC

www.kit.edu

Fortran 95/2003 Course

Exercises by Robert Barthel March 24, 2015

slide-2
SLIDE 2

2 24.03.15 Steinbuch Centre for Computing Exercises: Operators, Control Constructs

Exercise 1.1 Implement a program that reads a natural number n from STDIN and that prints out the sum of the first n natural numbers. Hint:

Reading of a variable from STDIN Sum of the first n natural numbers READ *, <VARIABLE>

slide-3
SLIDE 3

3 24.03.15 Steinbuch Centre for Computing Exercises: Operators, Control Constructs

Exercise 1.2 Implement a program that reads two real numbers from STDIN.

Print out the sum, the difference, the product and the ratio of the two numbers. Print out which number is greater or if both numbers are equal. If both numbers are positive or if both numbers are negative, print

  • ut a corresponding message with the result
slide-4
SLIDE 4

4 24.03.15 Steinbuch Centre for Computing Exercises: Operators, Control Constructs

Exercise 1.3 Implement the Euclidean algorithm for the computation of the greatest common divisor (GCD) of two integer numbers m and n. Print out the GCD. Hint:

Read two integer numbers from STDIN. Use an infinite DO-loop: Determine the remainder r of m/n. IF… THEN…ELSE-construct: If r is positive, compute the GCD of n and r in the next step. If r=0, the last divisor is the GCD of m and n (EXIT DO-loop). Remainder r of m/n by intrinsic function MOD:

r = MOD(m,n)

slide-5
SLIDE 5

5 24.03.15 Steinbuch Centre for Computing Exercises: Operators, Control Constructs

Exercise 1.4 Implement a program that reads many natural one-digit

  • numbers. If a number has more than one digit, only the last

digit should be taken. The reading stops if a negative number is read. Print out how often each digit occurred. Hint

Define counters for each digit and initialize them to zero Use an infinite DO-loop and EXIT Use MOD to determine last digit of read number Use SELECT CASE-construct