Created
April 15, 2013 08:09
-
-
Save takahisa/5386549 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> | |
void swap(int* a, int* b) { | |
int tmp; | |
tmp = *a; | |
*a = *b; | |
*b = tmp; | |
} | |
int euclid(int a, int b) { | |
int r; | |
if(a < b) { | |
swap(&a, &b); | |
} | |
while(b != 0) { | |
r = a % b; | |
a = b; | |
b = r; | |
} | |
return a; | |
} | |
int main(int argc, char** argv) { | |
int a, b, answer; | |
printf("input a: "); | |
scanf("%d", &a); | |
printf("input b: "); | |
scanf("%d", &b); | |
answer = euclid(a, b); | |
printf("answer : %d\n", answer); | |
return 0; | |
} |
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> | |
int euclid(int a, int b) { | |
return (b == 0) ? a : euclid(b, a % b); | |
} | |
int main(int argc, char** argv) { | |
int a, b, answer; | |
printf("input a: "); | |
scanf("%d", &a); | |
printf("input b: "); | |
scanf("%d", &b); | |
answer = euclid(a, b); | |
printf("answer : %d\n", answer); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment