Monday, September 12, 2011

calculate HCF using recursion, Highest common factor

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 p,int q)
    {
      int r;
      r=p%q;
      if(r==0)
          return(q);
      else
          gcd(q,r);
      }

No comments:

Post a Comment

Popular 5 Posts Last 7 days