The Greatest Common Divisor (GCD) of two whole numbers, also called the Greatest Common Factor (GCF) and the Highest Common Factor (HCF), is the largest whole number that's a divisor (factor) of both of them. For instance, the largest number that divides into both 20 and 16 is 4. (Both 16 and 20 have larger factors, but no larger common factors -- for instance, 8 is a factor of 16, but it's not a factor of 20.)
Source code:
class Program{
static void Main (){
int
a, b;
do{
Console.WriteLine("Input a: ");
a = int.Parse(Console.ReadLine());
Console.WriteLine("Input b: ");
b = int.Parse(Console.ReadLine());
} while (a
== 0 || b == 0);
Math.Abs(a);
Math.Abs(b);
while (a != b){
if (a > b) a = a - b;
else b = b - a;
}
Console.WriteLine("Highest Common Factor: {0}",a);
Console.ReadLine();
}
}
No comments:
Post a Comment