-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram28.cpp
More file actions
61 lines (50 loc) · 998 Bytes
/
program28.cpp
File metadata and controls
61 lines (50 loc) · 998 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
// LCM and HCF/GCF and its all factors
#include<iostream>
#include<algorithm>
using namespace std;
void LCM(int a, int b){
int i = a;
while(i<=a*b){
if(i%a==0 and i%b==0){
cout<<"LCM of these two numbers : "<<i<<endl;
break;
}
i++;
}
}
void HCF(int a,int b){
cout<<"HCF of these two numers : ";
for(int i = min(a,b);i>=1;i--){
if(a%i==0 and b%i==0){
cout<<i<<endl;
break;
}
}
}
void factors(int a , int b){
cout<<"Your factors of a : ";
for(int i = 1;i<=a;i++){
if(a%i==0){
cout<<i<<" ";
}
}
cout<<endl;
cout<<"Your factors of b : ";
for(int i = 1;i<=b;i++){
if(b%i==0){
cout<<i<<" ";
}
}
cout<<endl;
}
int main(){
int a,b;
cout<<"Enter first number : ";
cin>>a;
cout<<"Enter second number : ";
cin>>b;
factors(a,b);
LCM(a,b);
HCF(a,b);
return 0;
}