Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Does anybody know how to make a program in Pascal with this task?

Task :: MaxGCD

For given n integers, you have to find the pair that has the greatest GCD (greatest common divider).

INPUT:

the first line of the standard input will contain the number n, and the next n lines will contain the number, each being at most 1 000 000 000. n 1 000.

OUTPUT:

To the standard output, write the GCD of the pair that has the biggest GCD.

Input:

6

9

6

391

8

24

60

Output:

12

Input:

2

71

16899

Output:

1

1 Answer

Relevance
  • 1 decade ago
    Favorite Answer

    Try to modify this program which uses only 2 integers, you must use arrays.

    program GCDProgram (input, output);

    var

    x, y: integer;

    function Gcd (m, n : integer) : integer;

    var

    r: integer; {remainder}

    begin

    while n <> 0 do

    begin

    r := m mod n;

    m := n;

    n := r

    end;

    Gcd := m {returned result}

    end;

    begin{GcdProgram}

    writeln('PROGRAM GcdProgram');

    while true do {infinite loop - exit by an interrupt}

    begin

    write('Enter two integers: ');

    readln(x,y);

    writeln('GCD(', x:4, ',', y:4, ') = ', (Gcd(x, y)):4)

    end

    end. GcdProgram

Still have questions? Get your answers by asking now.