LCM is least common factor.
For example, L C M of 16 and 20 will be 2 x 2 x 2 x 2 x 5 = 80.
GCD is greatest common divisor of two or more integers, which are not all zero, is the largest positive integer that divides each of the integers.
For example, the G.C.D of 8 and 12 is 4.
Source Code:
- # include <stdio.h>
- int main()
- {
- int lcm,hcf,m,n,m1,n1;
- printf("Give the value= ");
- scanf ("%d %d",&m,&n);
- m1=m;
- n1=n;
- while(m1!=n1)
- {
- if(m1>n1)
- m1=m1-n1;
- else
- n1=n1-m1;
- }
- hcf=m1;
- lcm=(m*n)/hcf;
- printf("HCF=%d\t LCM=%d",hcf,lcm);
- return 0;
- }
Output:
1. Give the value=5 15
HCF=5 LCM=15
2. Give the value=15 50
HCF=5 LCM=150
0 comments:
Post a Comment