⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pr0518.cpp

📁 practice c++, it is from the book http://www.amazon.com/Schaums-Outline-Programming-John-Hubbard
💻 CPP
字号:
//  Programming with C++, Second Edition, by John R. Hubbard
//  Copyright McGraw-Hill, 2000
//  Problem 5.18 on page 113
//  The Greatest Common Divisor Function

#include <cassert>   // defines the assert() function
#include <iostream>  // defines the cin and cout objects
using namespace std;
long gcd(long,long);

int main()
{ int m, n;
  cout << "Enter two positive integers: ";
  cin >> m >> n;
  cout << "gcd(" << m << "," << n << ") = " << gcd(m,n) << endl;
}

long gcd(long m, long n)
{ // returns the greatest common divisor of m and n:
  if (m<n) swap(m,n);
  assert(n >= 0);
  while (n>0)
  { long r=m%n;
    m = n;
    n = r;
  }
  return m;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -