gcd
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
gcd
static int gcd(int a, int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
gcd
int gcd(int a,int b) {
while (a&&b) a>b?a%=b:b%=a;
return a+b;
}
gcd
import math
a = 10
b = 8
answer = math.gcd(10, 8)
print(answer)
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;
}
gcd
int gcd(int a,int b){
if(b==0) return a;
return gcd(b,a%b);
}
gcd
int gcd(int a, int b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
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+")");
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us