Program in C and C++ to find LCM of two numbers using Division method
C Program
#include<stdio.h> int LCM(int a,int b) { int i,lcm=1; for(i=2;i<=a&&i<=b;) { if(a%i==0&&b%i==0) { lcm*=i; a/=i; b/=i; } else i++; } lcm=lcm*a*b; return lcm; } int main() { int a,b,yes; start: printf("Enter two numbers :-"); scanf("%d%d",&a,&b); printf("LCM = %d",LCM(a,b)); printf("\nAgain calculate (1):- "); scanf("%d",&yes); if(yes==1) goto start; return 0; }
C++ Program
#include<iostream> using namespace std; int LCM(int a,int b) { int i,lcm=1; for(i=2;i<=a&&i<=b;) { if(a%i==0&&b%i==0) { lcm*=i; a/=i; b/=i; } else i++; } lcm=lcm*a*b; return lcm; } int main() { int a,b,yes; start: cout<<"Enter three number :-"; cin>>a>>b>>c; cout<<"HCF = "<<HCF(a,b,c); cout<<"\nAgain calculate (1):- "; cin>>yes; if(yes==1) goto start; return 0; }
Output :-
Related Programs
- Program in C and C++ to find HCF of three numbers using prime factorization method
- Program in C and C++ to find HCF of two number using Division method
- Program in C and C++ to find HCF of two numbers using prime factorization method
- Program in C and C++ to find LCM of three numbers using Division method
0 Comments