gcd in c++
#include<iostream>
using namespace std;
long long gcd(long long a, long long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
long long a,b;
cin>>a>>b;
cout<<gcd(a,b);
}
gcd in c++
#include<iostream>
using namespace std;
long long gcd(long long a, long long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
long long a,b;
cin>>a>>b;
cout<<gcd(a,b);
}
gcd function in c++
int gcd(int a, int b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
gcd in c++
#include<iostream>
using namespace std;
long long gcd(long long a, long long b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
int main()
{
long long a,b;
cin>>a>>b;
cout<<gcd(a,b);
}
gcd in c++
#include<iostream>
using namespace std;
int euclid_gcd(int a, int b) {
if(a==0 || b==0) return 0;
int dividend = a;
int divisor = b;
while(divisor != 0){
int remainder = dividend%divisor;
dividend = divisor;
divisor = remainder;
}
return dividend;
}
int main()
{
cout<<euclid_gcd(0,7)<<endl;
cout<<euclid_gcd(55,78)<<endl;
cout<<euclid_gcd(105,350)<<endl;
cout<<euclid_gcd(350,105)<<endl;
return 0;
}
gcd function in c++
int gcd(int a, int b)
{
// Everything divides 0
if (a == 0)
return b;
if (b == 0)
return a;
// base case
if (a == b)
return a;
// a is greater
if (a > b)
return gcd(a-b, b);
return gcd(a, b-a);
}
gcd c++
#include<bits/stdc++.h>
using namespace std;
long long UCLN(long long a,long long b)
{
long long r;
while (b!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
long long a, b;
cout<< "enter: ";
cin>> a;
cout<< "enter: ";
cin >>b;
cout<<UCLN(a,b)<<endl;
return 0;
}
gcd program in c
#include <stdio.h>
int main()
{
int t, n1, n2, gcd;
scanf("%d", &t); // Test Case Input
while (t--)
{
scanf("%d %d", &n1, &n2);// Taking numbers input
if (n2 > n1)
{
gcd = n1;
n1 = n2;
n2 = gcd;
}
while (n1 % n2 != 0)
{
gcd = n2;
n2 = n1 % n2;
n1 = gcd;
}
// n2 is our gcd
printf("GCD: %d\n", n2);
}
return 0;
}
gcd in c++
#include<iostream>
using namespace std;
int euclid_gcd(int a, int b) {
if(a==0 || b==0) return 0;
int dividend = a;
int divisor = b;
while(divisor != 0){
int remainder = dividend%divisor;
dividend = divisor;
divisor = remainder;
}
return dividend;
}
int main()
{
cout<<euclid_gcd(0,7)<<endl;
cout<<euclid_gcd(55,78)<<endl;
cout<<euclid_gcd(105,350)<<endl;
cout<<euclid_gcd(350,105)<<endl;
return 0;
}
gcd c++
#include<bits/stdc++.h>
using namespace std;
long long UCLN(long long a,long long b)
{
long long r;
while (b!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
long long a, b;
cout<< "enter: ";
cin>> a;
cout<< "enter: ";
cin >>b;
cout<<UCLN(a,b)<<endl;
return 0;
}
gcd = 1
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+")");
}
}
gcd program in c
#include <stdio.h>
int main()
{
int t, n1, n2, gcd;
scanf("%d", &t); // Test Case Input
while (t--)
{
scanf("%d %d", &n1, &n2);// Taking numbers input
if (n2 > n1)
{
gcd = n1;
n1 = n2;
n2 = gcd;
}
while (n1 % n2 != 0)
{
gcd = n2;
n2 = n1 % n2;
n1 = gcd;
}
// n2 is our gcd
printf("GCD: %d\n", n2);
}
return 0;
}
gcd = 1
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