07MoreArrays-handout

# 07MoreArrays-handout - More on Arrays Amir Hossein Rabbani...

This preview shows pages 1–8. Sign up to view the full content.

More on Arrays Amir Hossein Rabbani Winter 2009

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Array : Review Is the type of the values that can be stored in each element of the array Specifies the range of the indices for the subscript Type :: Name ( Bound ) REAL :: course_grades(10) course_grade(1) = 92 A1 A2 An-1 An 1 2 n-1 n Index elements
This session More examples on arrays Nested DO loop Implied DO loop

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
G C D G reatest C ommon D ivisor : the largest number that divides two integers Given two numbers a and b , and provided that a <= b , it is sufficient to divide both a and b by all numbers that are equal to or less than a . 204 12 x 17 12 ------- = ------------- = ------- 119 7 x 17 7
Example A B / A Common Divisor 12 18 / 12 - 11 18 / 11 - 10 18 / 10 - 9 18 / 9 - 8 18 / 8 - 7 18 / 7 - 6 18 / 6 6 = G C D 5 18 / 5 - 4 18 / 4 - 3 18 / 3 3 2 18 / 2 2 1 18 / 1 1 A = 12 B = 18

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
! Greatest Common Divisor PROGRAM GCD IMPLICIT NONE INTEGER :: A, B, counter IF (A <= B) THEN ! Finding minimum of A and B counter = A ELSE counter = B END IF DO IF (MOD(A , counter) == 0 .AND. MOD(B , counter) == 0) EXIT counter = counter - 1 END DO WRITE (*,*) “GCD of”, A, “ and “, B, “ is “, counter END PROGRAM GCD
all common divisors? QuickTimeª and a

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/15/2010 for the course COMP COMP 206 taught by Professor Vybihal during the Spring '04 term at McGill.

### Page1 / 17

07MoreArrays-handout - More on Arrays Amir Hossein Rabbani...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online