---
title: "Create a program to find the GCD (Greatest Common Divisor) of two numbers."  
description: "Create a program to find the GCD (Greatest Common Divisor) of two numbers."  
author: "Utpal Vishwas"  
published: 2023-06-14  
updated: 2023-06-15  
canonical: https://www.mindstick.com/forum/158748/create-a-program-to-find-the-gcd-greatest-common-divisor-of-two-numbers  
category: "c#"  
tags: ["c#", "programs"]  
reading_time: 1 minute  

---

# Create a program to find the GCD (Greatest Common Divisor) of two numbers.

Create a [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) to find the GCD ([Greatest](https://www.mindstick.com/articles/12976/the-greatest-games-at-vegas-paradise) [Common](https://www.mindstick.com/articles/23170/10-most-common-accounting-mistakes-of-small-business) Divisor) of two numbers.

## Replies

### Reply by Aryan Kumar

Sure, here is a C# program to find the GCD of two numbers:

C#

```plaintext
using System;

public class GCD {

    public static void Main() {

        // Get two numbers from the user
        Console.WriteLine("Enter two numbers: ");
        int num1 = Convert.ToInt32(Console.ReadLine());
        int num2 = Convert.ToInt32(Console.ReadLine());

        // Find the GCD using Euclid's algorithm
        int gcd = 1;
        while (num2 != 0) {
            int temp = num1 % num2;
            num1 = num2;
            num2 = temp;
            gcd = num1;
        }

        // Print the GCD
        Console.WriteLine("The GCD of {0} and {1} is {2}", num1, num2, gcd);
    }
}
```

This program will first prompt the user to enter two numbers. It will then use Euclid's algorithm to find the GCD of the two numbers. Euclid's algorithm works by repeatedly finding the remainder of the division of one number by the other. The algorithm terminates when the remainder is 0, which means that the two numbers are relatively prime. The GCD is then equal to the last non-zero remainder.

The program will then print the GCD of the two numbers.


---

Original Source: https://www.mindstick.com/forum/158748/create-a-program-to-find-the-gcd-greatest-common-divisor-of-two-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
