CPlusOne
Notes, Syllabus, Questions, Ideas,
Books, Reference materials on Electronics


Quick Links
#Login #Sign up #Forum #Feedback

 

Write a program to find the HCF and LCM of the given numbers using functions

#include<stdio.h>
#include<conio.h>
int fhcf(int a,int b)
{
int l,i,hcf;
if(a>b)
l=a;
else
l=b;
10  for(i=2;i<=l;i++)
11  {
12  if(a%i==0 && b%i==0)
13  {
14  hcf=i;
15  }
16  }
17  return hcf;
18  }
19  int flcm(int a,int b)
20  {
21  int p=0,i,lcm;
22  p=a*b;
23  for(i=1;i<=p;i++)
24  {
25  if(i%a==0 && i%b==0)
26  {
27  lcm=i;
28  break;
29  }
30  }
31  return lcm;
32  }
33  void main()
34  {
35  clrscr();
36  int a,b,hcf,lcm;
37  printf("\nEnter two numbers:");
38  scanf("%d %d",&a,&b);
39  hcf=fhcf(a,b);
40  lcm=flcm(a,b);
41  printf("\nHCF of %d and %d is: %d",a,b,hcf);
42  printf("\nLCM of %d and %d is: %d",a,b,lcm);
43  getch();
44  }

Find More from our code collection
Armstrong number, binary number to a decimal number, bubble sort, decimal number to binary number, factorial of the given number factors, fibonacci numbers, HCF and LCM, matrix, mergesort, salary of the employee. palindrome, quadratic equation, star patterns, series etc. and much more...
#Return to Example Source Code