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

Flowchart to find HCF and LCM of two numbers

HCF and LCM of two numbers flowchart

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 

Programs based on looping in C C++

  1. Generate series of natural numbers (while, for, do while)
  2. Generate series of natural numbers and their sum
  3. Generate series of odd numbers and find their sum
  4. Generate series of even numbers and find their sum
  5. Generate table of given number
  6. Find factorial of given number
  7. Find power of given number
  8. Generate multiplication table of given number
  9. Generating Fibonacci series
  10. Checking prime number
  11. Generating series of prime numbers
  12. Sum of digits of given number
  13. Reverse of digits of given number
  14. Checking palindrome number
  15. Checking Armstrong number
  16. Generating series of Armstrong numbers
  17. Convert decimal to binary
  18. Convert binary to decimal
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer