1

Edit BoxesI am developing an application which consists of Edit Texts, I will explain clearly based on steps:

a) Based on Spinner some item will contain 3 edit text boxes, and some will contain 4 edit-text boxes.

b) for this i will to calculate GCD, Currently i am using using GCD calculation for two Edit boxes, how can i calculate for ** Three Edit Boxes and Four Edit Boxes**

private long gcd(long a, long b) {

        if (b == 0)
            return a;
        else
            return gcd(b, a % b);
    }

How i can write code for Three and four Edit Boxes.

NikhilReddy
  • 6,904
  • 11
  • 38
  • 58
  • By "Edit Boxes." DYM values? – Andrew Thompson Apr 30 '13 at 07:47
  • possible duplicate of [Euclidian greatest common divisor for more then two numbers](http://stackoverflow.com/questions/1231733/euclidian-greatest-common-divisor-for-more-then-two-numbers) or [Greatest common divisor of multiple (more than 2) numbers](http://stackoverflow.com/questions/11098274/greatest-common-divisor-of-multiple-more-than-2-numbers) – maba Apr 30 '13 at 07:50

3 Answers3

1

You can combine the two-argument gcd function:

gcd(a, b, c, d) = gcd(gcd(gcd(a, b), c), d)

This works for basically any number of arguments using a recursive implementation.

Matthias Meid
  • 12,455
  • 7
  • 45
  • 79
0

If you are finding the gcd of four numbers (a,b,c,d) then split should work.

Try this way:

gcd(a,b,c,d) = gcd(gcd (a,b) , gcd(c,d))
Achintya Jha
  • 12,735
  • 2
  • 27
  • 39