adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to find LCM of two numbers using Division method

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
   

Post a Comment

0 Comments