Finding GCD/HCF of two integer numbers – CSKC
Sign In

Search

Code Learning #CPP#2871    siteicon   siteicon  

Finding GCD/HCF of two integer numbers

Program to find Highest Common Factor (HCF), also called the Greatest Common Divisor between the two numbers entered by the user.

Learning Objectives

  • Finding HCF/GCD of two numbers by successive subtraction of smaller number from the larger one until they are equal.

Source Code

TC++ #2871

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

Code Understanding

int x,y; cout<<“Enter two numbers separated by space: “; cin>>x>>y;
Two numbers are collected from the user.
while(x != y) //This loop will exit until x and y are both same
{
if(x>y) x=x-y;  else y=y-x;
This is successive iteration of x and y in a way that x and y keep reducing until they are equal
}
cout<<“GCD/HCF = “<< x;
Here we print the result


Suggested Filename(s): hcf-gcd.cpp



Share

Created: 20-Jan-2018 23:28 | Updated: 21-Jan-2018 00:05|