C++ program to find HCF (Highest Common Factor) of two numbers

Last modified on May 27th, 2020 Download This Tutorial in PDF

Write a C++ program to find HCF (Highest Common Factor) of two numbers.

Highest Common Factor HCF C++

Flowchart of the program to find HCF of two numbers

Flowchart of the C++ program to find HCF of two numbers

Source Code of the program to find HCF of two numbers

Output

enter no:

9

7

HCF is:1

Excercise

Find the possible mistakes in the following Shamil’s Flow Table of the program to find HCF (Highest Common Factor) of two numbers.

Loop if What lines will execute Actual work to do
n1=12,n2=24;

i=1;

true 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. 12, 13A, 13B, 14, 15, 16, 17, 18, 19T, 13A, 13B, 14, 15, 16, 17,  18, 19F, 20, 21

 

n1%i==0&&n2%i==0

12%1==0&&24%1==0

0&&0

n1=13,n2=3;

i=2;

false 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11. 12, 13A(F),13B(F),17,18,19T,12,13A(f),13B(f),17, 18,19F,20,21

 

n1%i==0&&n2%i==0

13%1==0&&3%1==0

1&&1

 

Subscribe for Friendship

Latest posts by Prof. Fazal Rehman Shamil (see all)