New Member FAQ | Forums | Earn Revenue | Posting Guidelines | Help Topics | Admissions 2013
Awards & Gifts
 
Login Login    Register      

ArticlesPractice TestsAsk ExpertsQuestion PapersJobsUniversitiesCollegesCoursesSchoolsTraining

Active Members
TodayLast 7 Daysmore...

Join our online Google+ community for Bloggers, Content Writers and Webmasters




To find the HCF and LCM by C language program


Posted Date:     Total Responses: 0    Posted By: vijay anand   Member Level: Gold   Points/Cash: 2   


This project is about to find the Highest Common Factor(HCF) or Least Common Multiplication(LCM).You should give the input for finding the hcf or lcm and it gives the output.





#include
#include
void main()
{
int n,a[5],i,j,op,c,t;
long int x,k;
clrscr();
printf("\n\nEnter how many numbers:\t");
scanf("%d",&n);
for(i=0;i<5;i++)
a[i]=0;
printf("\n\nEnter the numbers one by one:\n");
for(i=0;i scanf("%d",&a[i]);
do
{
printf("\n\nChoose:\n\n1.HCF\n\n2.LCM\n\n3.Exit\n\nEnter your option:\t");
scanf("%d",&op);
switch(op)
{
case 1:
t=a[0];
for(i=1;i if(t>a[i])
t=a[i];
for(i=t;i>0;i--)
{
c=0;
if(t%i==0)
{
for(j=0;j {
if(a[j]%i==0)
c=1;
else
{
c=0;
break;
}
}
}
if(c==1)
{
printf("\n\nHCF : %d",i);
break;
}
}
break;
case 2:
x=1;
for(i=0;i x=x*a[i];
t=a[0];
for(i=1;i if(t t=a[i];
for(k=t;k<=x;k++)
{
c=0;
if(k%t==0)
{
for(j=0;j {
if(k%a[j]==0)
c=1;
else
{
c=0;
break;
}
}
}
if(c==1)
{
printf("\n\nLCM : %ld",k);
break;
}
}
break;
}
}while(op!=3);
getch();
}


Project Feedbacks


No feedbacks found. Be the first to respond...

Post Feedback
You must Sign In to post a feedback.
Next Project: Human mind reader
Previous Project: Canteen management project using C language

Return to Project Index

Post New Project


Related Projects

Subscribe to Email
  • Get Jobs by Email
  • Forum posts by Email
  • Articles by Email
  • Online MembersK Mohan
    sanskar
    Komal Sood
    Aditya
    Anzil H
    Runa N Borah
    dharam singh
    Vikas Srivastava
    Nityananda Hazarika
    nithya
    Vandana
    More...


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    AdSense Revenue Sharing sites   Advertise   Talk to Tony John
    ISC Technologies, Kochi - India. Copyright © All Rights Reserved.