Created
April 27, 2022 05:58
-
-
Save SomeBottle/9cddb3b47a50a1205fe19e3392a215c1 to your computer and use it in GitHub Desktop.
欧几里得算法求最大公约数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
long int CommonDiv(long int num1, long int num2) { // 寻找两数最大公约数 | |
long int dividend; // 被除数 | |
long int divisor; // 除数 | |
long int remainder; // 余数 | |
if (num1 > num2) { | |
dividend = num1; | |
divisor = num2; | |
} else { | |
dividend = num2; | |
divisor = num1; | |
} | |
do { | |
remainder = dividend % divisor; | |
dividend = divisor; | |
divisor = remainder ? remainder : divisor; | |
} while (remainder != 0); | |
return divisor; | |
} | |
int main() { | |
printf("%d", CommonDiv(245, 100)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment