Problem 30

6 comments on “Problem 30”


  • shushank

    a,b,c=map(int,input().split(” “))
    d=min(a,b,c)
    l=[]
    for i in range(2,d+1):
    if a%i==0 and b%i==0 and c%i==0:
    l.append(i)
    print(max(l))


  • amit

    #include
    #include
    int gretest (int[], int n);
    int
    main ()
    {
    int gcd;
    int arr[] = { 4, 8, 12, 16, 20 };
    int n, j, res, k = 0;
    int count = 0;
    n = sizeof (arr) / sizeof (int);
    gcd = gretest (arr, n);
    //printf(“%d”,gcd);
    for (j = gcd; j >= 1; j–)
    {
    count = 0;
    for (int k = 0; k < n; k++)
    {
    if (arr[k] % j != 0)
    break;
    count++;
    }
    if (count == n)
    break;
    }
    printf ("%d", j);
    return 0;
    }

    int
    gretest (int arr[], int n)
    {
    int start;
    start = arr[0];
    for (int i = 0; i < n – 1; i++)
    {
    if (start < arr[i + 1])
    start = arr[i + 1];
    }
    return start;
    }


  • rohan

    #include
    int gcd(int a,int b)
    {
    if(a==0)
    return b;
    return gcd(b%a,a);
    }
    int main()
    {
    int n,x,i,t;
    printf(“of how much numbers you want to find GCD”);
    scanf(“%d”,&t);
    int arr[t];
    for(i=0;i<t;++i)
    scanf("%d",&arr[i]);
    x=arr[0];
    n=sizeof(arr)/sizeof(arr[0]);
    for(i=1;i<n;++i)
    {
    x=gcd(arr[i],x);
    }
    printf("%d",x);
    return 0;
    }


  • 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;

    }