Answers for "gcd(40, 3)"

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;
}
Posted by: Guest on July-17-2021
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;
}
Posted by: Guest on July-17-2021
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+")");
    }
}
Posted by: Guest on July-20-2021
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+")");
    }
}
Posted by: Guest on July-20-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language