Skip to content

Instantly share code, notes, and snippets.

Created Jan 13, 2015
What would you like to do?
Program to calculate GCD using Euclid algorithm
#include <stdio.h>
int gcd(int l,int s){
return s;
int q=l/s;
int r=l%s;
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