Thursday, September 22, 2016

GDC ( Greatest Common Divisor )

Write  a  program  to  find  the GCD ( Greatest  Common  Divisor ) of  many  positive  integers .


Programming  Coding .... 

Program GCD_Program
    Implicit none
    Integer :: n , a(100) , i , c , gcd
    Write ( * , 2 ) 'How  many  numbers  input  for  GCD ?'
    2 Format ( A40 )
    Read ( * , *)  n
    Write( * , 3 ) 'Input numbers :'
    3 Format ( / , A20 )
    Read ( *, * ) ( a(i) , i = 1 , n )
    Do i = 1 , ( n - 1 )
     7   c = mod (a(i) , a(i+1))
        If  ( c == 0 ) then
            gcd = a( i + 1)
            Else
                a(i) = a ( i +1 )
                a( i+1 ) = c
                Goto 7
                End if
                End do
                Write ( * , 12 ) 'GCD = ' , gcd
                12 Format ( / , A7 , I7 )

                End Program


 Input ::





Output ::                                                           
                                    


3 comments:

  1. Come on, FORTRAN 77 or older, goto, format and messed up indentation? Is it supposed to be a joke or trolling?

    ReplyDelete