Problem 30

3 comments on “Problem 30”


  • VIVEK KUMAR

    int[] myArray = { 16,8,4,32 };
    // Arrays.sort(myArray);
    int size = myArray.length;
    int result = myArray[0];
    int i = 1;
    while(i<size)
    {
    if(myArray[i]%result==0)
    {
    i++;
    } else {
    result = myArray[i]%result;
    i++;
    }
    }
    System.out.println("GCD is "+result);


  • anusha anusha

    #python
    def find_gcd(x, y):
    while(y):
    x, y = y, x % y

    return x

    l = [2, 4, 6, 8, 16]

    num1=l[0]
    num2=l[1]
    gcd=find_gcd(num1,num2)

    for i in range(2,len(l)):
    gcd=find_gcd(gcd,l[i])

    print(gcd)


  • Rishav Raj Singh

    #include
    int main()

    {

    int n,i,gcd;

    printf(“Enter how many no.s u want to find gcd : “);

    scanf(“%d”,&n);

    int arr[n];

    printf(“\nEnter your numbers below :- \n “);

    for(i=0;i<n;i++)

    {

    printf("\nEnter your %d number = ",i+1);

    scanf("%d",&arr[i]);

    }

    gcd=arr[0];

    int j=1;

    while(j<n)

    {

    if(arr[j]%gcd==0)

    {

    j++;

    }

    else

    {

    gcd=arr[j]%gcd;

    i++;

    }

    }

    printf("\nGCD of k no.s = %d ",gcd);

    return 0;

    }