给定两个正整数,编程求它们的最大公约数.
|
#include int main() { int m, n; int m_cup, n_cup, res; /*被除数, 除数, 余数*/ printf("Enter two integer:\n"); scanf("%d %d", &m, &n); if (m > 0 && n >0) { m_cup = m; n_cup = n; res = m_cup % n_cup; while (res != 0) { m_cup = n_cup; n_cup = res; res = m_cup % n_cup; } printf("Greatest common divisor: %d\n", n_cup); printf("Lease common multiple : %d\n", m * n / n_cup); } else printf("Error!\n"); return 0; } 沈誠瑋 2008-05-21 18:29 |
》热 点 关 注
》编 辑 推 荐
》相 关 图 文
