-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathP19LOOP.cpp
More file actions
64 lines (47 loc) · 909 Bytes
/
P19LOOP.cpp
File metadata and controls
64 lines (47 loc) · 909 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// To find GCD or HCF of two numbers
// using FOR LOOP:
// #include <iostream>
// using namespace std;
// int main() {
// int n1,n2,hcf;
// cout<<"enter 2 numbers: ";
// cin>>n1>>n2;
// //swapping variables n1 and n2 if n2 is greater than n1
// if (n2>n1)
// {
// int temp=n2;
// n2=n1;
// n1=temp;
// }
// for (int i =1 ; i <=n2; ++i)
// {
// if (n1%i==0 && n2%i==0)
// {
// hcf=i;
// }
// }
// cout<<"HCF: "<<hcf;
// return 0;
// }
//****************************************************************************************************************************
//using WHILE LOOP **:
#include <iostream>
using namespace std;
int main() {
int n1,n2;
cout<<"enter 2 numbers: ";
cin>>n1>>n2;
while (n1!=n2) //***
{
if (n1>n2)
{
n1-=n2;
}
else
{
n2-=n1;
}
}
cout<<"HCF: "<<n1;
return 0;
}