Last active
November 1, 2015 05:17
-
-
Save Prince781/3ccd1fcf7d379f9909f9 to your computer and use it in GitHub Desktop.
gcd
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
| /* gcd.c | |
| * run `make gcd` */ | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| long gcd (long a, long b) { | |
| ldiv_t qr; | |
| while (b != 0) { | |
| qr = ldiv(a, b); | |
| a = b; | |
| b = qr.rem; | |
| } | |
| return a; | |
| } | |
| int main(int argc, char *argv[]) { | |
| if (argc != 3) { | |
| printf ("usage: %s [a] [b]\n", argv[0]); | |
| exit(1); | |
| } | |
| long a = atol(argv[1]); | |
| long b = atol(argv[2]); | |
| long val = gcd (a, b); | |
| printf("gcd(%ld, %ld) = %ld\n", a, b, val); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment