Created
June 17, 2012 03:29
-
-
Save numa08/2943296 to your computer and use it in GitHub Desktop.
Euclid
This file contains 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 change(int *numA, int *numB){ | |
int temp; | |
temp = *numB; | |
*numB = *numA; | |
*numA = temp; | |
} | |
// | |
//メインの実装 | |
//割り算を行なって、余りを保存。 | |
//割り切れるかどうかによって、分岐を行う | |
//再起の関数 | |
// | |
int eucrid(int numA, int numB) | |
{ | |
int rest; | |
if(numA < numB) | |
{ | |
change(&numA,&numB); | |
} | |
rest = numA % numB; | |
if(rest == 0){ | |
return numB; | |
} | |
return eucrid(numB, rest); | |
} | |
int main(void){ | |
int numA = 18, numB = 30; | |
printf("%d\n",eucrid(numA,numB)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment