Advertisement
llvlleo1810

Tìm ước chung lớn nhất và bội chung nhỏ nhất

Apr 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.38 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int a,b,c;
  4.  
  5. void input() {
  6.  cin >> a >> b;
  7. }
  8.  
  9. int UCLN(int a, int b) {
  10.  while ( a != b) {
  11.   if (a > b)
  12.    a = a - b;
  13.   else
  14.    b = b - a;
  15.  }
  16.  
  17.  return a;
  18. }
  19.  
  20. int BCNN(int a, int b) {
  21.  c = a * b / UCLN(a,b);
  22.  return c;
  23. }
  24.  
  25. int main() {
  26.  input();
  27.  int t = UCLN(a, b);
  28.  cout << t;
  29.  int h = BCNN(a,b);
  30.  cout << " " << h;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement