Greatest Common Divisor(GCD) of Two Numbers
来源:互联网 发布:好听的名字知乎 编辑:程序博客网 时间:2024/05/20 01:39
#include <stdio.h>#include <stdlib.h>int gcd(int a, int b);int gcdRecursive(int, int);int gcdRecursiveHelper(int, int);void swap(int* a, int* b);int main(){ int a = gcd(56,12); int b = gcdRecursive(18, 12); printf("%d %d\n", a, b); return 0;}int gcd(int a, int b){ if(a < b) swap(&a, &b); int result = a%b; while(result != 0){ a = b; b = result; result = a % b; } return b;}int gcdRecursive(int a, int b){ if(a < b){ swap(&a, &b); } return gcdRecursiveHelper(a, b);}int gcdRecursiveHelper(int a, int b){ int result = a%b; if(result != 0){ return gcdRecursiveHelper(b, result); }else{ return b; }}void swap(int* a, int* b){ int tmp; tmp = *a; *a = *b; *b = tmp;}
- Greatest Common Divisor(GCD) of Two Numbers
- GCD (Greatest Common Divisor)
- [计算最大公因子]Finding the greatest common divisor (gcd) of 2 numbers
- Calculate the Greatest Commom Divisor (GCD) and Lowest Common Multiple (LCP) of Two Integers
- P32 (**) Determine the greatest common divisor of two positive integer numbers.
- GCD Algorithm(Greatest Common Divisor)
- GCD (greatest common divisor)【求最大公约数】
- 求最大公约数Greatest Common Divisor(GCD)
- Euclid Greatest Common Divisor-GCD - 欧几里得 最大公约数
- The greatest common divisor gcd(最大公约数)
- Greatest Common Divisor (GCD) - Euclidean algorithm
- 最大公约数GCD(Greatest Common Divisor)算法小结
- Greatest Greatest Common Divisor
- Greatest Greatest Common Divisor HD5207
- Eculid算法递归地求解GCD(Greatest Common Divisor,最大公约数)
- Greatest common divisor
- The Greatest Common Divisor
- Solving Greatest Common Divisor
- Bigcommerce系统瘦身方法——加快运行速度
- chapt14、探索虚拟内存
- 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序
- 关于多线程实现火车票售票模拟
- 问题总结
- Greatest Common Divisor(GCD) of Two Numbers
- 实施开发组队
- 关于消费者.生产者,缓冲区的简单java实现
- 强制的类型转换
- 修复数据库脚本
- linux内核返回错误参数
- "main" org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file
- C++中的临时对象(拷贝构造函数)(上)
- 关于dijit.form.Select中addOption()的一点注意事项