Monday, September 12, 2011

Calculate HCF of two numbers

main()
{
    int a,b;
    clrscr();
    printf("\n Enter any two nos.:");
    scanf("%d %d",&a,&b);
    printf("\n HCF of the two nos.:%d",gcd(a,b));
    getch();
}

    gcd(int n,int d)
    {
      int r;
      do{
         r=n%d;
         n=d;
         d=r; }while(r!=0);
      return(n);
      }

No comments:

Post a Comment

Popular 5 Posts Last 7 days