Write a C C++ program to find HCF and LCM of two numbers

Write a C C++ program to find HCF and LCM of two numbers

Looping और iterative statements के बारे में और अधिक जानने के लिए देखें— Looping statements in C

C Language में Token क्या होता है जानने के लिए देखें—Data types in C

C Language में उपलब्ध Operators और इनके विभिन्न प्रकारो को जानने के लिए देखें—Operators in C

C program to find HCF and LCM of two numbers

``````#include<stdio.h>
int main()
{
int a,b,i=1,hcf,lcm;
printf("Enter two numbers: ");
scanf("%d%d",&a,&b);
while(i<=a&&i<=b)
{
if(a%i==0&&b%i==0)
{
hcf=i;
}
i++;
}
lcm=(a*b)/hcf;
printf("HCF = %d\n",hcf);
printf("LCM = %d\n",lcm);
return 0;
}``````

C++ program to find HCF and LCM of two numbers

``````#include<iostream>
using namespace std;
int main()
{
int a,b,i=1,hcf,lcm;
cout<<"Enter two numbers: ";
cin>>a>>b;
while(i<=a&&i<=b)
{
if(a%i==0&&b%i==0)
{
hcf=i;
}
i++;
}
lcm=(a*b)/hcf;
cout<<"HCF = "<<hcf<<"\n";
cout<<"LCM = "<<lcm<<"\n";
return 0;
}``````

Output C C++ program to find HCF and LCM of two numbers

```Enter two numbers: 40 60
HCF = 20
LCM = 120```
```Enter two numbers: 16 24
HCF = 8
LCM = 48 ```
```Enter two numbers: 90 60
HCF = 30
LCM = 180 ```

Share it to: