Pages

Subscribe:

Find HCF Using C Program

HCF (Highest Common Factor ) also called GCM (Greatest Common Measure ) or GCD (Greatest Common Divisor).HCF two of more non zero numbers is the greatest number that divides the number without remember.



Example
  • Assume we have 2 numbers 12, 18. 
  • The numbers 12 and 18 can divided by 2,3,6. 
  • Here 6 is the highest number that can divided both numbers 12 and 18, so 6 is the HCF of 12 18.
Program :

#include<stdio.h>
#include<conio.h>
int hcf(int , int );
void main()
{
    int a,b,c;
    char ch;
   do{
    
         clrscr();
         printf("\n Enter 1st no:");
         scanf("%d",&a);
         printf("\n enter 2nd no:");
         scanf("%d",&b);
         c=hcf(a,b);
         printf(" \n <%d> and <%d> HCF value [%d]",a,b,c);
         printf(" \n  Continue (Y/N) :");
        ch=getch();
    }while(ch=='y'||ch=='Y');
}
int hcf(int x,int y)
{
    int b,s,r;

    if(x>y)
    {
         b=x;
         s=y;
    }
    else
    {
        b=y;
        s=x;
    }
    r=b%s;
    while(r!=0)
    {
        b=s;
        s=r;
        r=b%s;
    }
    return s;
}


Output :







If you have any Further Information and Quires about this Article don't hesitate to comment in comment box below.
                                                           AND

 If you like this article , like our Facebook like page and click  +1 to support 123techguide
comments powered by Disqus
 

Listed In

Bloggers - Meet Millions of Bloggers http://Link-exchange.comxa.com
Blog Search: The Source for Blogs Internet Blogs

Disclaimer

The contents in this blog are taken from various sources available over the internet, therefore we do not gurantee of it's accuracy, if you find any of the content in the blog is infringing it's copyright, please do email us on '123techguide@gmail.com' and we will make sure to remove the same from the blog at the earliest.