Problem 15

24 comments on “Problem 15”


  • rohan

    #include
    int main()
    {
    int i,l,m,x,y,z;
    printf(“enter 3 numbers”);
    scanf(“%d%d%d”,&x,&y,&z);
    if(x<y)
    {
    if(x<z)
    m=x;
    else
    m=z;
    }
    else
    if(y<z)
    m=y;
    else
    m=z;
    for(i=1;i<=m;++i)
    {
    if(x%i==0&&z%i==0&&z%i==0)
    l=i;
    }
    printf("\n%d",l);
    return 0;
    }


  • Pogakula

    #python3
    def gcd(nums):
    lis=[]
    for i in nums:
    final=[]
    for j in range(1,i+1):
    if i%j==0:
    final.append(j)
    else:
    continue
    lis.append(final)
    finals=[set(x) for x in lis[1:]]
    return ‘the gcd of the given terms is {}’.format(max(list(set(lis[0]).intersection(*finals))))
    list1=[]
    n=int(input(‘enter the number of terms:\t’))
    for i in range(n):
    inp=int(input(‘enter the number:\t’))
    list1.append(inp)
    print(gcd(list1))


  • Sameer

    #include

    using namespace std;
    int gcd(int a,int b) {
    int rem;
    if(a > b) {
    int temp = b;
    b = a;
    a = temp;
    }
    while(a) {
    rem = b%a;
    b = a;
    a = rem;
    }
    return b;
    }

    int main()
    {
    int a,b,c,ans;
    cin>>a>>b>>c;
    ans = gcd(gcd(a,b),c);
    cout<<ans;
    return 0;
    }


  • Sadique Gametor

    #include
    int main()
    {
    int a,b,c,hcf;
    scanf(“%d %d %d”,&a,&b,&c);
    hcf=(a<b)?(a<c)?a:c:(b<c)?b:c;
    while(1)
    {
    if(a%hcf==0 && b%hcf==0 && c%hcf==0)
    break;
    hcf–;
    }
    printf("%d",hcf);
    return 0;
    }


  • Bathula

    #python Program

    from fractions import gcd
    def LCMofArray(a):
    lcm = a[0]
    for i in range(1,len(a)):
    lcm = gcd(lcm, a[i])
    return lcm

    arr1 = [120,60,40,20]
    print(“LCM of arr1 elements:”, LCMofArray(arr1))


  • Bathula

    #python

    from fractions import gcd
    def LCMofArray(a):
    lcm = a[0]
    for i in range(1,len(a)):
    lcm = gcd(lcm, a[i])
    return lcm

    arr1 = [120,60,40,20]
    print(“LCM of arr1 elements:”, LCMofArray(arr1))


  • Tirtha

    SOLUTION IN PYTHON

    l = []
    n = int(input(‘Enter the size of array of which you want to find GCD: ‘))

    for i in range(n):
    x = int(input())
    l.append(x)

    x = l[0]
    y = l[1]

    def GCD(x,y):

    if x<y:
    x, y = y, x

    while y!=0:
    x,y = y, x%y

    return x

    gcd = GCD(x,y) #finding gcd of first 2 numbers

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

    print(gcd)


  • Mohd Saif

    n1,n2,n3=map(int,input().split(“,”))
    if(n1<n2 and n2<n3 and n1<n3):
    x=n1
    elif(n1n3 and n1n2 and n2<n3 and n1<n3):
    x=n2
    elif(n1n3 and n1>n3):
    x=n3
    elif(n1>n2 and n2n3):
    x=n2
    elif(n1>n2 and n2>n3 and n1>n3):
    x=n3
    for i in range(1,x+1):
    if(n1%i==0 and n2%i==0 and n3%i==0):
    gcd=i
    print(f”GCD for {n1},{n2},{n3} is:{gcd}”)


  • Mohd Saif

    #python

    n1,n2,n3=map(int,input().split(“,”))
    if(n1<n2 and n2<n3 and n1<n3):
    x=n1
    elif(n1n3 and n1n2 and n2<n3 and n1<n3):
    x=n2
    elif(n1n3 and n1>n3):
    x=n3
    elif(n1>n2 and n2n3):
    x=n2
    elif(n1>n2 and n2>n3 and n1>n3):
    x=n3
    for i in range(1,x+1):
    if(n1%i==0 and n2%i==0 and n3%i==0):
    gcd=i
    print(f”GCD for {n1},{n2},{n3} is:{gcd}”)


  • sai

    #include
    int main()
    {
    int n1, n2,n3,i, gcd;
    printf(“Enter two integers: “);
    scanf(“%d %d %d”, &n1, &n2,&n3);
    for(i=1; i <= n1 && i <= n2 && i<=n3; ++i)
    {
    // Checks if i is factor of both integers
    if(n1%i==0 && n2%i==0 && n3%i==0)
    gcd = i;
    }
    printf("G.C.D of %d and %d is %d %d", n1, n2,n3,gcd);
    return 0;
    }


  • sai

    ,n3,i, gcd;
    printf(“Enter two integers: “);
    scanf(“%d %d %d”, &n1, &n2,&n3);
    for(i=1; i <= n1 && i <= n2 && i<=n3; ++i)
    {
    // Checks if i is factor of both integers
    if(n1%i==0 && n2%i==0 && n3%i==0)
    gcd = i;
    }
    printf("G.C.D of %d and %d is %d %d", n1, n2,n3,gcd);
    return 0;
    }

    its simple way to gets GCD……//////


  • Ayantika

    #include

    int main()
    {
    int a,b,c, gcd;
    scanf(“%d %d %d”,&a,&b,&c);
    for(int i=1; i <=a && i <=b && i<=c; ++i)
    {
    // Checks if i is factor of both integers
    if(a%i==0 && b%i==0 && c%i==0)
    gcd = i;
    }
    printf("G.C.D is %d",gcd);
    return 0;
    }