About 25,900,000 results
Open links in new tab
  1. Given two numbers a and b, the task is to find the GCD of the two numbers.

    Note: The GCD (Greatest Common Divisor) or HCF (Highest Common Factor) of two numbers is the largest number that divides both of them.

    Examples:

    Input: a = 20, b = 28Output: 4Exp...

    // C++ program to find GCD of two numbers\
    #include <bits/stdc++.h>
    using namespace std;
    // Function to return gcd of a and b
    int gcd(int a, int b)
    {
    // Find Minimum of a and b
    int result = min(a, b);
    while (result > 0) {
    if (a % result == 0 && b % result == 0) {
    // C program to find GCD of two numbers
    #include <math.h>
    #include <stdio.h>
    // Function to return gcd of a and b
    int gcd(int a, int b)
    {
    // Find Minimum of a and b
    int result = ((a < b) ? a : b);
    while (result > 0) {
    if (a % result == 0 && b % result == 0) {
    // Java program to find GCD of two numbers
    import java.io.*;
    public class GFG {
    // Function to return gcd of a and b
    static int gcd(int a, int b)
    {
    // Find Minimum of a and b
    int result = Math.min(a, b);
    while (result > 0) {
    if (a % result == 0 && b % result == 0) {
    # Python program to find GCD of two numbers
    # Function to find gcd of two numbers
    def gcd(a, b):
    # Find minimum of a and b
    result = min(a, b)
    while result:
    if a % result == 0 and b % result == 0:
    break
    result -= 1
    # Return the gcd of a and b
    return result
    # Driver Code
    // C# program to find GCD of two numbers
    using System;
    public class GFG {

    // Function to return gcd of a and b
    static int gcd(int a, int b)
    {
    // Find Minimum of a and b
    int result = Math.Min(a, b);
    while (result > 0) {
    if (a % result == 0 && b % result == 0) {
    // Javascript program to find GCD of two numbers
    // Function to return gcd of a and b
    function gcd(a,b)
    {
    // Find Minimum of a and b
    let result = Math.min(a, b);
    while (result > 0) {
    if (a % result == 0 && b % result == 0) {
    break;
    }
    result--;
    }

    // Return gcd of a and b
    Content Under CC-BY-SA license
    Was this helpful?
  2. Program to Find GCD or HCF of Two Numbers - GeeksforGeeks

  3. C Program to Find GCD of two Numbers

  4. GCD of Two Numbers in C - GeeksforGeeks

    Jul 2, 2024 · The GCD of two numbers is the largest positive integer that completely divides both numbers without leaving a remainder. In this article, we will learn to calculate the GCD of two numbers in the C programming language.

  5. GCD of Two Numbers in C++ - GeeksforGeeks

  6. C Program to find GCD of Two Numbers - Tutorial …

    Aug 1, 2016 · Learn how to write a C program to calculate the greatest common divisor (GCD) of two positive integers using different methods, such as for loop, while loop, functions, and recursion. See examples, explanations, and output …

  7. C Program to Find the GCD of Two Numbers - Embedded Tech Hub

  8. People also ask
  9. C Program to Find G.C.D Using Recursion

  10. GCD of Two Numbers in C with Example - Sanfoundry

    GCD stands for Greatest Common Divisor. GCD of two numbers in C is the largest positive integer that completely divides both the given numbers. Example: GCD (10,15) = 15, GCD (12,15) = 3. Write a C Program to Find the …

  11. C program to find GCD of numbers using non-recursive function

  12. Euclidean algorithms (Basic and Extended) - GeeksforGeeks