/* Program to find LCM/HCF of 15 Nos in C++/ C (replace cin with scanf & cout with printf for c) */ /* Developed by - Kishore Kr. Banerjee - papillon_kish@yahoo.com */ #include <iostream.h> #include <conio.h> main() { int num[3],i,j,p,q,tmp,n1,n2,LCM,rem,flag; clrscr(); for(i=0;i<3;i=i+1) { cout<<"Enter No - "<<i+1<<"="; cin>>num[i]; } clrscr(); n1=num[0]; p=n1; for(i=1;i<3;i=i+1) { n2=num[i]; /* Finding HCF */ q=n2; if(p<q) { tmp=q; q=p; p=tmp; } while(p%q!=0) { rem=p%q; q=p; p=rem; if(p<q) { tmp=q; q=p; p=tmp; } } /*finding LCM */ LCM=1; for(j=1;n1%j==0n2%j==0;j=j+1) { if(n1%j==0) { n1=n1/j; flag=1; } if(n2%j==0) { n2=n2/j; flag=1; } if(flag==1) { LCM=LCM*j; } } LCM=LCM*n1*n2; n1=LCM; } cout<<"the LCM ="<<LCM; cout<<"the hcf ="<<q; getch(); } ----- int gcd (int a, int b) { . int tmp; . if (a<0) a= -a; . if (b<0) b= -b; . if (a<b) tmp= a, a= b, b= tmp; . while (b) { . . tmp= a%b; . . a= b; . . b= tmp; . } . return a; } int gcd_n (int n, const int *vect) { . int i, gcdtmp; . for (i=0, gcdtmp=0; i<n && gcdtmp!=1; ++i) . . gcdtmp= gcd (gcdtmp, vect[i]); . return gcdtmp; } int LCM (int a, int b) { . int d= gcd (a, b); . if (d==0) return d; . else return a/d*b; } int lcm_n (int n, const int *vect) { . int i, lcmtmp; . for (i=0, lcmtmp=1; i<n; ++i) . . lcmtmp= LCM (lcmtmp, vect[i]); . return lcmtmp; }
p = 4
p=1
6
6 = p - 17 + 1-------------------5 = p - 17-------------------p = 22
#include <iostream.h> #include <conio.h> main() { int num[3],i,j,p,q,tmp,n1,n2,LCM,rem,flag; clrscr(); for(i=0;i<3;i=i+1) { cout<<"Enter No - "<<i+1<<"="; cin>>num[i]; } clrscr(); n1=num[0]; p=n1; for(i=1;i<3;i=i+1) { n2=num[i]; /* Finding HCF */ q=n2; if(p<q) { tmp=q; q=p; p=tmp; } while(p%q!=0) { rem=p%q; q=p; p=rem; if(p<q) { tmp=q; q=p; p=tmp; } } /*finding LCM */ LCM=1; for(j=1;n1%j==0n2%j==0;j=j+1) { if(n1%j==0) { n1=n1/j; flag=1; } if(n2%j==0) { n2=n2/j; flag=1; } if(flag==1) { LCM=LCM*j; } } LCM=LCM*n1*n2; n1=LCM; } cout<<"the LCM ="<<LCM; cout<<"the hcf ="<<q; getch(); } ----- int gcd (int a, int b) { . int tmp; . if (a<0) a= -a; . if (b<0) b= -b; . if (a<b) tmp= a, a= b, b= tmp; . while (b) { . . tmp= a%b; . . a= b; . . b= tmp; . } . return a; } int gcd_n (int n, const int *vect) { . int i, gcdtmp; . for (i=0, gcdtmp=0; i<n && gcdtmp!=1; ++i) . . gcdtmp= gcd (gcdtmp, vect[i]); . return gcdtmp; } int LCM (int a, int b) { . int d= gcd (a, b); . if (d==0) return d; . else return a/d*b; } int lcm_n (int n, const int *vect) { . int i, lcmtmp; . for (i=0, lcmtmp=1; i<n; ++i) . . lcmtmp= LCM (lcmtmp, vect[i]); . return lcmtmp; }
No.-------------------------------------------------------------To find the HCF and LCM of two (or more) numbers list the numbers in their prime factorisations in power format; then:HCF = product of the primes to the LOWEST power across all the numbers;LCM = product of the primes to the HIGHEST power across all the numbers.Note: for p being any prime, p⁰ = 1; so if a prime does not appear as a factor of a number, it can be said to have a power of 0. This means that the LOWEST power is 0 and the prime does not appear in the HCF of the numbers. The HIGHEST power of a prime must be at least the LOWEST power of a prime.Thus if a prime appears in the HCF of the numbers (with a power greater than or equal to 1) it MUST also appear in the LCM of the numbers.If the HCF of some numbers is 15, then: 15 = 3 × 5 which means that the primes 3 and 5 MUST both apear in the LCM.But 175 = 5² × 7, which does NOT include 3, so 175 CANNOT be the LCM of some numbers which have a HCF of 15.
/* Program to find LCM/HCF of 15 Nos in C++/ C (replace cin with scanf & cout with printf for c) */ /* Developed by - Kishore Kr. Banerjee - papillon_kish@yahoo.com */ #include <iostream.h> #include <conio.h> main() { int num[3],i,j,p,q,tmp,n1,n2,LCM,rem,flag; clrscr(); for(i=0;i<3;i=i+1) { cout<<"Enter No - "<<i+1<<"="; cin>>num[i]; } clrscr(); n1=num[0]; p=n1; for(i=1;i<3;i=i+1) { n2=num[i]; /* Finding HCF */ q=n2; if(p<q) { tmp=q; q=p; p=tmp; } while(p%q!=0) { rem=p%q; q=p; p=rem; if(p<q) { tmp=q; q=p; p=tmp; } } /*finding LCM */ LCM=1; for(j=1;n1%j==0n2%j==0;j=j+1) { if(n1%j==0) { n1=n1/j; flag=1; } if(n2%j==0) { n2=n2/j; flag=1; } if(flag==1) { LCM=LCM*j; } } LCM=LCM*n1*n2; n1=LCM; } cout<<"the LCM ="<<LCM; cout<<"the hcf ="<<q; getch(); } ----- int gcd (int a, int b) { . int tmp; . if (a<0) a= -a; . if (b<0) b= -b; . if (a<b) tmp= a, a= b, b= tmp; . while (b) { . . tmp= a%b; . . a= b; . . b= tmp; . } . return a; } int gcd_n (int n, const int *vect) { . int i, gcdtmp; . for (i=0, gcdtmp=0; i<n && gcdtmp!=1; ++i) . . gcdtmp= gcd (gcdtmp, vect[i]); . return gcdtmp; } int LCM (int a, int b) { . int d= gcd (a, b); . if (d==0) return d; . else return a/d*b; } int lcm_n (int n, const int *vect) { . int i, lcmtmp; . for (i=0, lcmtmp=1; i<n; ++i) . . lcmtmp= LCM (lcmtmp, vect[i]); . return lcmtmp; }
Shell program to find LCM and hcf of two no.s tput clear echo "Enter first no" read a echo "Enter 2nd no" read b p= 'expr $a \* $b' while [$b -ne 0] do r= 'expr $a % $b' a=$b b=$r done LCM = 'expr $p / $a' echo "LCM = $LCM" echo "Hcf = $a"
The GCF is 1. The LCM is p x q x r.
To find the simplest form of the fraction p/q first find the highers common factor of p and q. If HCF(p, q) = 1 then the fraction is already in its simplest form and there is nothing to be done. Otherwise, divide p by the HCF to give r, divide q by HCF to give s and the simplest form is r/s.
p = 4
take A=1,P=1X=1 1+1+1=3 sin 90=1, a+p+x 90+90+90=270
p=1
If 5*(p + 6) = 25 then p is -1
6
1/5