Sunday, 22 October 2017

Calculating GCD / HCF

#include<stdio.h>
int main(int a,char *b[])
{
    int no1,no2,min,i,gcd=1;
    if(a!=3)
    {
        exit(1);
    }
    no1=atoi(b[1]);
    no2=atoi(b[2]);
    min=(no1<no2)?no1:no2;
    for(i=1;i<=min;i++)
    {
        if((no1%i)==0 && (no2%i)==0)
            gcd=i;
    }
    printf("%d",gcd);
    return 0;


}

No comments:

Post a Comment

Featured Post

TCS Latest Test Patern ( For On-Campus Drives )

Tata Consultancy Services is software services consulting company whose  headquarter is situated in Mumbai, India. It is the Asia’s larges...