by Dinesh Thakur Category: Functions

 

#include<iostream.h>

#include<conio.h>
int func_hcf(int u,int v);
void main()
{
       int p,q,hcf,n;
       int s[10];
       clrscr();
       cout<<"Specify the number of elements:";
       cin>>n;
       cout<<"Specify the elements:";
       for(p=0;p<n;p++)
       cin>>s[p];
       for(p=0;p<n-1 ;p++)
           {
                hcf=func_hcf(s[p],s[p+ 1]);
                s[p+ 1]=hcf;
           }
               cout<<"Highest Common Factor is: "<<hcf;
               getch();
}
       int func_hcf(int u,int v)
          {
              if(u%v==0)
                 return(v);
              else
            return(func_hcf(v, u%v));
          }

Find HCF Using Recursion



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles