{"id":7575,"date":"2021-09-30T10:40:44","date_gmt":"2021-09-30T05:10:44","guid":{"rendered":"https:\/\/python-programs.com\/?p=7575"},"modified":"2021-11-22T18:35:33","modified_gmt":"2021-11-22T13:05:33","slug":"python-program-to-calculate-the-hcf-gcd","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-hcf-gcd\/","title":{"rendered":"Python Program to Calculate the HCF\/GCD"},"content":{"rendered":"

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output<\/a> & achieve your goal in improving java coding skills.<\/p>\n

Highest Common Factor (HCF) \/ Greatest Common Divisor (GCD) :<\/strong><\/p>\n

When at least one of the integers is not zero, the greatest positive integer that evenly divides the numbers without a remainder is called the Highest Common Factor or Greatest Common Divisor.<\/p>\n

The GCD of 12 and 16 is, for example, 4.<\/p>\n

Given two numbers the task is to find the highest common factor of the two numbers in Python.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 24\u00a0 \u00a0b=36<\/pre>\n

Output:<\/strong><\/p>\n

The Highest Common Factor (HCF) of the numbers 24 36 = 12<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 18 b=72<\/pre>\n

Output:<\/strong><\/p>\n

The Highest Common Factor (HCF) of the numbers 18 72 = 18<\/pre>\n

Example3:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 4 b=8<\/pre>\n

Output:<\/strong><\/p>\n

The Highest Common Factor (HCF) of the numbers 4 8 = 4<\/pre>\n

Example4:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

a= 9 b=9<\/pre>\n

Output:<\/strong><\/p>\n

The Highest Common Factor (HCF) of the numbers 9 9 = 9<\/pre>\n

Explanation:<\/strong><\/p>\n

 The Highest common factor of two numbers is number itself if both the numbers are equal<\/pre>\n

Python Program to Calculate the HCF\/GCD<\/h2>\n

There are several ways to calculate the hcf of the two numbers in python some of them are:<\/p>\n