Answers for "GCD"

0

GCD

import java.util.Scanner;
public class   Euclid {
    static public void main(String[] argh){
        System.out.print("Enter two numbers: ");
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int TEMP = 0 ;
        int GCD = 0;
        int max = a>b?a:b;
        int min = a<b?a:b;
        while(min!=0){
            TEMP=(max%min);
            GCD = min ;
            min = TEMP;
        }
        System.out.print("("+GCD+")");
    }
}
Posted by: Guest on July-20-2021
0

gcd

static int gcd(int a, int b)
    {
      if (b == 0)
        return a;
      return gcd(b, a % b); 
    }
Posted by: Guest on December-16-2020
0

gcd

int gcd(int a,int b) {
	while (a&&b) a>b?a%=b:b%=a;
	return a+b;
}
Posted by: Guest on April-03-2021
0

gcd

import math

a = 10
b = 8
answer = math.gcd(10, 8)
print(answer)
Posted by: Guest on April-02-2021
0

gcd

//using euclid's theorem to find gcd
#include <iostream>

using namespace std;
int gcd(int x,int y)
{
    if(y==0)
    {
        return x;
    }
    return gcd(y,x%y);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin>>t;
    while(t--)
    {
        int a,b;
        cin>>a>>b;
        int ans=gcd(a,b);
        cout<<ans<<endl;
    }
    return 0;
}
Posted by: Guest on June-07-2021
0

gcd

int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
Posted by: Guest on September-28-2020
0

gcd

int gcd(int a, int b) {
    while (b) b ^= a ^= b ^= a %= b;
    return a;
}
Posted by: Guest on April-03-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language