===========================================================================
CODING
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
//Calculate LCM and HCF
int HCF(int a,int b);
void main()
{
clrscr();
int a,b,lcm,hcf;
cout<<"Enter 2 Numbers: ";
cin>>a>>b;
hcf=HCF(a,b);
lcm=a*b/hcf;
cout<<"LCM of these Numbers is: "<<lcm<<" and HCF is: "<<hcf;
getch();
}
int HCF(int a,int b)
{
int hcf=1;
for(hcf=a>b?b:a;hcf!=1;hcf--)
if(a%hcf==0 && b%hcf==0)
break;
return hcf;
}
CODING
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<stdlib.h>
#include<dos.h>
//Calculate LCM and HCF
int HCF(int a,int b);
void main()
{
clrscr();
int a,b,lcm,hcf;
cout<<"Enter 2 Numbers: ";
cin>>a>>b;
hcf=HCF(a,b);
lcm=a*b/hcf;
cout<<"LCM of these Numbers is: "<<lcm<<" and HCF is: "<<hcf;
getch();
}
int HCF(int a,int b)
{
int hcf=1;
for(hcf=a>b?b:a;hcf!=1;hcf--)
if(a%hcf==0 && b%hcf==0)
break;
return hcf;
}
===========================================================================
No comments:
Post a Comment