Created
January 13, 2015 18:52
-
-
Save pranavk/ced334250ac8e52943d9 to your computer and use it in GitHub Desktop.
Program to calculate GCD using Euclid algorithm
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> | |
int gcd(int l,int s){ | |
if(l%s==0){ | |
return s; | |
} | |
int q=l/s; | |
int r=l%s; | |
gcd(s,r); | |
} | |
int main(int argc, char *argv[]){ | |
if(argc<3 || argc > 3 ){ | |
printf("Only two integer arguments are allowed.\n"); | |
return 1; | |
} | |
// Program starts here : | |
int a=atoi(argv[1]); | |
int b=atoi(argv[2]); | |
int s=a<b?a:b; | |
int l=a+b-s; | |
int res=gcd(l,s); | |
printf("Result is : %d\n",res); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment