Skip to content

Instantly share code, notes, and snippets.

@pranavk
Created January 13, 2015 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pranavk/ced334250ac8e52943d9 to your computer and use it in GitHub Desktop.
Save pranavk/ced334250ac8e52943d9 to your computer and use it in GitHub Desktop.
Program to calculate GCD using Euclid algorithm
#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