-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkmm-bmm.cpp
70 lines (58 loc) · 1.25 KB
/
kmm-bmm.cpp
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
65
66
67
68
69
70
#include <iostream>
#include<conio.h>
using namespace std;
int SahihMosbatBoodan(int num) {
while(true){
if(num>=0){
break;
}
else{
cout<<"Enter a Positive number please ! :";
cin>>num;
}
}
return num;
}
int funbmm(int n1,int n2){
int temp, r = 1, min , max;
max=n1;
min=n2;
while(r!=0)
{
r=(max%min);
max=min;
min=r;
}
return max;
}
int funkmm(int n1,int n2){
int max;
if(n1 > n2) max = n1;
else max = n2;
while(true){
if(max % n1 == 0 && max % n2 == 0) break;
else ++max;
}
return max;
}
int main() {
int num_1, num_2 , bemimmim , kemimmim;
cout << "Type a Positive Number: ";
cin >> num_1;
num_1 = SahihMosbatBoodan(num_1);
cout << "Type a Positive Number Again: ";
cin >> num_2;
num_2 = SahihMosbatBoodan(num_2);
if(num_1 == 0 || num_2 == 0)
{
cout << "Really ? bemimmim va kemimmim ba 0 ? Nemishe!!";
}
else
{
bemimmim = funbmm(num_1,num_2);
kemimmim = funkmm(num_1,num_2);
cout << "B.M.M n1 va n2 = " << bemimmim << endl;
cout << "K.M.M n1 va n2 = " << kemimmim;
}
return 0;
}