C# program to find the greatest common divisor (GCD)
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
Program:
The source code to find the Greatest Common Divisor is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
Here, we created a class GcdClass that contain an instance method GetGcd() and a static method Main().
In the GetGCD() method, we passed two numbers, and find the Greatest Common Divisor of two numbers, then return the GCD to the calling method.
The GCD of two numbers is the highest positive number that can divide both numbers without any remainder.
Coming to the Main() method, In the Main() method, we read the values of two integer numbers and then find the GCD using GetGcd() method and the print the GCD on the console screen.